Re: Notifications and Subclassing

2011-03-08 Thread Gordon Apple
Yup.  Right you are.  Thanks.

This was originally a singleton class where it wouldn't have shown up. That
changed in redesign when we started switching different subclasses, which
caused the problem.


On 3/8/11 10:07 AM, "glenn andreas"  wrote:

> 
> On Mar 8, 2011, at 9:42 AM, Gordon Apple wrote:
> 
>> Class A:  NSObject, has methods:
>> 
>> -  (void)foo:(Notification*)notification {
>>...
>> }
>> 
>> - (void)addObservers {
>>[[NSNotificationCenter defaultCenter] addObserver:self
>> selector:@selector(foo:)
>> name:notificationName
>>   object:nil];
>> }
>> 
>> 
>> Class B: subclass of A.  This is the class used.
>> 
>> Notification sent from elsewhere.  Console:
>> 
>> -[NSCFString foo:]: unrecognized selector sent to instance 0x69807c0
>> 
>> 
>> Is this due to confusion of of which class received the notification?  Or is
>> this a compiler/linker bug?  I even tried declaring foo in A¹s headers, to
>> no avail.  This same overall procedure is used elsewhere (without
>> subclassing), with no problems.  What am I missing?
>> 
>> 
>> 
> 
> That's a classic memory management problem.
> 
> Most likely, you're forgetting to unregister your observer when you are
> deallocating it (resulting in a notification center to have a stale pointer
> that is later reused by an NSString).
> 
> 
> Glenn Andreas  gandr...@gandreas.com
> The most merciful thing in the world ... is the inability of the human mind to
> correlate all its contents - HPL
> 



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Notifications and Subclassing

2011-03-08 Thread glenn andreas

On Mar 8, 2011, at 9:42 AM, Gordon Apple wrote:

> Class A:  NSObject, has methods:
> 
> -  (void)foo:(Notification*)notification {
>...
> }
> 
> - (void)addObservers {
>[[NSNotificationCenter defaultCenter] addObserver:self
> selector:@selector(foo:)
> name:notificationName
>   object:nil];
> }
> 
> 
> Class B: subclass of A.  This is the class used.
> 
> Notification sent from elsewhere.  Console:
> 
> -[NSCFString foo:]: unrecognized selector sent to instance 0x69807c0
> 
> 
> Is this due to confusion of of which class received the notification?  Or is
> this a compiler/linker bug?  I even tried declaring foo in A’s headers, to
> no avail.  This same overall procedure is used elsewhere (without
> subclassing), with no problems.  What am I missing?
> 
> 
> 

That's a classic memory management problem.

Most likely, you're forgetting to unregister your observer when you are 
deallocating it (resulting in a notification center to have a stale pointer 
that is later reused by an NSString).


Glenn Andreas  gandr...@gandreas.com 
The most merciful thing in the world ... is the inability of the human mind to 
correlate all its contents - HPL

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Notifications and Subclassing

2011-03-08 Thread Gordon Apple
Class A:  NSObject, has methods:

-  (void)foo:(Notification*)notification {
...
}

- (void)addObservers {
[[NSNotificationCenter defaultCenter] addObserver:self
 selector:@selector(foo:)
 name:notificationName
   object:nil];
}


Class B: subclass of A.  This is the class used.

Notification sent from elsewhere.  Console:

-[NSCFString foo:]: unrecognized selector sent to instance 0x69807c0


Is this due to confusion of of which class received the notification?  Or is
this a compiler/linker bug?  I even tried declaring foo in A¹s headers, to
no avail.  This same overall procedure is used elsewhere (without
subclassing), with no problems.  What am I missing?




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com