Re: Where is it better to register with NSNotificationCenter in class?
Re: Where is it better to register with NSNotificationCenter in class?
- Subject: Re: Where is it better to register with NSNotificationCenter in class?
- From: Samvel <email@hidden>
- Date: Tue, 25 Mar 2008 00:16:25 -0500
Reason: I thought that at some point NSNotificationCenter has to be
instantiated in an application loading process and my constructor may
have executed at earlier stage.
Answer: Unfortunately the reason was much simpler than that. It turned
out to be an example (answer) to my prev. question regarding memory
management. At some point later in my constructor an array is supposed
to be created. Basically it has to be a collection of string and I did
it this way:
dimensions = [NSArray arrayWithObjects: @"1920x1440",
@"1600x1200",
@"1280x1024",
@"1024x768"];
[dimensions retain];
So, strings are not actually retained. :( and this led to odd behavior.
Samvel.
On Mar 25, 2008, at 12:06 AM, Sherm Pendley wrote:
On Tue, Mar 25, 2008 at 12:51 AM, Samvel <email@hidden> wrote:
Hi,
I run into troubles trying to register my object with
NSNotificationCenter in class
-(id) init;
Basically here is my constructor:
-(id) init
{
self = [super init];
if( self) {
[[NSNotificationCenter defaultCenter]
addObserver: self
selector : @selector( downloadStarted:)
name : @"DownloadStarted"
object : nil];
//... (at this point self has lost it's original value
having
some '<value')
What leads you to believe that is the case?
}
return self;
}
So, what method is the best place to put registration with
NSNotificationCenter to?
What method is the best place to use a for() loop? Seriously - the
answer is the same, you put it wherever makes the most sense in your
app.
What kind of problem led to this question? No offense intended, but
I'm honestly having trouble figuring out just what it is that you're
asking here. Adding self as an observer object doesn't change the
value of self, and there are no special requirements about the "best
place" to register for notifications.
Ultimately I wish it would be done on
automatic basis in similar way as with:
-(id) init;
There's no reason an object can't or shouldn't register itself for
notifications. Again - what makes you think it would cause problems?
sherm--
_______________________________________________
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