• 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: -(NSString *)description method not called in Cocoa app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -(NSString *)description method not called in Cocoa app


  • Subject: Re: -(NSString *)description method not called in Cocoa app
  • From: Chris Giordano <email@hidden>
  • Date: Mon, 20 Dec 2004 10:24:14 -0500

Brian,

On Dec 19, 2004, at 10:09 PM, Brian Andresen wrote:

My project has two targete, a Cocoa app and a command-line-only
testing app.  I wrote a custom -description method for my class, but
it's only getting called in the latter one.  I haven't yet figured out
the reason.

There's a function which generates an XML file, which is used in both
the testing app and the full app.  For each object in a NSArray, it
grabs the -description and appends a new element to the XML file
containing the description.  A simplified view of this is:

writeXmlFile()
{
    ....
    NSEnumerator* objEnum = [theArray objectEnumerator];
    MyObject* obj;
    while ( obj = [objEnum nextObject] )
	[xmlStr appendFormat:@"  <foo>%@</foo>\n", [obj description]];
    ....
}

In the CLI app, -[MyObject description] gets called just like I
expect.  In the Cocoa app, the same writeXmlFile() function is called,
but now [obj description] returns the NSObject default, like
<MyObject: 0x5c5a20>.

Any ideas on what's different?  Why doesn't my method get called in
the Cocoa app?  (I put a breakpoint and a NSLog in the -description
method to verify that it was never called.)


Is it the case that your Cocoa application uses bindings and an object of this class participates in bindings or Key-Value Observation in some way? If so, this is a known bug. It was discussed a while ago, and some info can be found at <http://www.cocoabuilder.com/archive/message/cocoa/2004/8/29/115963>, or an earlier discussion at <http://lists.apple.com/archives/cocoa-dev/2004/Jul/msg01763.html> which also refers to an even earlier discussion.


The short version (until the bug is fixed): don't do that. (That is, implement and use something other than -description.)

chris


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: -(NSString *)description method not called in Cocoa app
      • From: Brian Andresen <email@hidden>
References: 
 >-(NSString *)description method not called in Cocoa app (From: Brian Andresen <email@hidden>)

  • Prev by Date: Re: Do you care if user changes the SystemFont?
  • Next by Date: Re: -(NSString *)description method not called in Cocoa app
  • Previous by thread: Re: -(NSString *)description method not called in Cocoa app
  • Next by thread: Re: -(NSString *)description method not called in Cocoa app
  • Index(es):
    • Date
    • Thread