Re: NSObject description not working
Re: NSObject description not working
- Subject: Re: NSObject description not working
- From: Eric Wang <email@hidden>
- Date: Fri, 30 Jan 2004 02:33:16 -0500
on 1/10/04 11:20 PM, matt neuburg at email@hidden wrote:
>
The following code shows the problem. The first two parts are just warm-up, to
>
show what *should* happen. The third part is the problem.
>
>
MyObject* obj = [[MyObject alloc] init];
>
NSLog([obj description]); // "howdy"
>
>
NSArray* arr = [NSArray arrayWithObject: obj];
>
[obj release];
>
obj = [arr objectAtIndex: 0];
>
NSLog([obj description]); // "howdy"
>
NSLog([[obj class] description]); // "MyObject"
>
>
NSLog([[theList objectAtIndex: 0] description]); // "<MyObject: 0x387ef0>"
>
NSLog([[[theList objectAtIndex: 0] class] description]); // "MyObject"
>
>
In the next-to-last line, instead of executing the description method and
>
returning "howdy", the object returns this thing in angle-brackets. Yet it is
>
a MyObject, just as before. So why is this?
>
>
The only difference that seems relevant is that theList is populated and
>
maintained by an NSArrayController / NSObjectController. But how could this be
>
relevant? If a thing is a MyObject instance, shouldn't it respond to a
>
MyObject instance method, no matter how it was created? m.
Hi Matt,
Sorry about the delayed reply; I recently came across the same problem. The
-description method of one of my classes was not being called properly when
debugging. It seems that when using bindings, a class that is being observed
is replaced by a custom subclass NSNotifying_YourClassNameHere at runtime.
That subclass implements -description to print out the object address, thus
overriding your class's description method, resulting in the behavior you
are seeing.
Hope this helps,
Eric Wang
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.