Re: iOS - the joy of observers and NSInternalInconsistancyException for KVO
Re: iOS - the joy of observers and NSInternalInconsistancyException for KVO
- Subject: Re: iOS - the joy of observers and NSInternalInconsistancyException for KVO
- From: Jonathan Mitchell <email@hidden>
- Date: Thu, 19 May 2016 17:55:28 +0100
>
> Is there any safer KVO technique to prevent or detect the dreaded "An instance of xxxxxx was deallocated while key value observers were still registered with it"?
>
I have a ton of observers in NSViewController subclasses.
Generally when I use an observer I make 100% sure I have a strong property reference (held by the NSViewController instance) to the observed object.
That way I know that the observed object will live as long as the NSViewController.
That way the observed object can get deallocated before the observer.
I then always make sure to remove my observers in NSViewController -dealloc.
If you want the observer to stop observing on command then use a delegate pattern or a notification to explicitly request that.
It is a futile task IMHO to dig into the KVO machinery and try and second guess it.
Jonathan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden