I have a crash:
Fatal Exception: NSInternalInconsistencyException
An instance 0x151eabd0 of class UIView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x151b6c10> ( <NSKeyValueObservance 0x14384cd0: Observer: 0x151b0090, Key path: hidden, Options: <New: YES, Old: YES, Prior: NO> Context: 0x151b0180, Property: 0x8814fc0> )
In my view I have this code:
deinit {
stackView.arrangedSubviews.forEach { view in
stackView.removeArrangedSubview(view)
}
}
After investigation I found that method removeArrangedSubview does not call removeHiddenListener. Why?
You are removing listeners by code:
deinit {
// This removes `hidden` value KVO observers using didSet()
{ self.arrangedSubviews = [] }()
}
But arrangedSubviews are already empty. Why don't you remove listeners for all listeners in registeredKvoSubviews array?