• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSObject description not working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: Drawing a selection rectangle
  • Next by Date: Re: Any new/updated Cocoa books soon?
  • Previous by thread: Re: NSObject description not working
  • Next by thread: Re: NSObject description not working
  • Index(es):
    • Date
    • Thread