Re: Avoiding KVO in dealloc?
Re: Avoiding KVO in dealloc?
- Subject: Re: Avoiding KVO in dealloc?
- From: Kiel Gillard <email@hidden>
- Date: Tue, 4 Aug 2009 11:32:41 +1000
On 04/08/2009, at 10:59 AM, Kyle Sluder wrote:
On Mon, Aug 3, 2009 at 5:47 PM, Kiel Gillard<email@hidden>
wrote:
Do you have a documentation reference for that? I would have
expected the
isa swizzling to be an implementation detail of the runtime that is
handled
before my subclass inits. Of course, what I expect and what happens
in
reality do not always match ;-)
The Objective-C 2.0 Programming Guide prescribes the use of direct
ivar access inside an initializer[1] and inside dealloc[2].
[1] http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html#/
/apple_ref/doc/uid/TP30001163-CH22-SW14
[2] http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html#/
/apple_ref/doc/uid/TP30001163-CH17-SW16
Thanks for these - much appreciated. The -dealloc commentary was very
helpful. For the OP, this means care should be taken to unobserve key
paths before dealloc. One way this could be done by observing
NSApplicationWillTerminateNotification.
The constraints and conventions commentary for the init method seems
to be more about coding style (consistency in style during
initialisation and deallocation) as one could argue the side affects
of a custom accessor are desired (such as registering a new object
value of an instance variable for KVO notifications).
As far as your point about when swizzling occurs, it can only happen
at the point of a KVO observer registration: the runtime can't predict
the future.
When if I observe some property of Foo *bar at some point in time, KVO
swizzles the isa to KVONotifying_Foo. Then, if I observe a different
property of the same object at some other point in time, are you
suggesting KVO swizzles the isa to KVONotifying_Foo2 which in turn
"can often" break future KVO notifications?
Kiel
_______________________________________________
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