Re: NSDocument's -close method calls itself?
Re: NSDocument's -close method calls itself?
- Subject: Re: NSDocument's -close method calls itself?
- From: "Sean McBride" <email@hidden>
- Date: Thu, 9 Jul 2009 14:36:13 -0400
- Organization: Rogue Research Inc.
On 7/2/09 11:52 AM, Quincey Morris said:
>On Jul 2, 2009, at 10:34, Sean McBride wrote:
>
>> I'm trying to find somewhere to undo what was done in my NSDocument
>> subclass' initializer. Specifically, to start/stop KVO
>> observation. It
>> seemed like 'close' would be a good place.
>
>'close' isn't a good place, because it isn't necessarily called. If
>you look at the Leopard Developer Release Notes:
>
> http://developer.apple.com/releasenotes/Cocoa/AppKit.html
>
>in the section entitled "Advice for Overriders of Methods that Follow
>the delegate:didSomethingSelector:contextInfo: Pattern", you'll find a
>nice little code snippet that happens to show you where to place code
>that should execute just before a document closes:
>
>> if (shouldClose) {
>> // Here we can do all sorts of things with this document that's
>> about to be closed.
>> }
>
>Does that help?
Yes, thanks! However, just as 'close' is not always called, neither is
canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo. It's not
called if the document is explicitly closed (i.e. if someone sends the
document the 'close' message).
Again, my goal is to find a place to stop KVO started in my
initializer. Were I not a GC app, I guess I could use dealloc. I can't
use finalize, as removeObserver: is not documented to be thread safe.
I guess I'll do this:
- (void)close
{
if (!_didDoSpecialCloseStuffExactlyOnce)
{
[controller removeObserver:....];
_didDoSpecialCloseStuffExactlyOnce = YES;
}
[super close];
}
The bool should protect me from super calling into 'close' again (see
subject).
Thanks,
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
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