Re: A documentation dumdum
Re: A documentation dumdum
- Subject: Re: A documentation dumdum
- From: Jeff LaMarche <email@hidden>
- Date: Sun, 22 Jun 2008 12:13:45 -0400
On Jun 22, 2008, at 12:02 PM, William Squires wrote:
okay, looking up tableView:setObjectValue:forTableColumn:row shows
that setObjectValue: takes an (id), but what is it really? An
NSString pointer? I want to get an NSString that represents the new
value the user typed in for the selected (and edited) cell in the
NSTableView. Can I safely typecast this to (NSString *)? In which
case, maybe the docs should say that this is an (NSString *) instead
of (id)?
The documentation is correct. The Table View Programming Guide states:
The NSTableView object treats objects provided by its data source as
values to be displayed in NSCell objects. If these objects aren’t of
common value classes—such as NSString, NSNumber, and so on—you may
need to create a custom NSFormatter object to display them. For more
information, see Data Formatting Programming Guide for Cocoa.
In other words, it's not always going to be an NSString *. Whatever
the object is, it will be converted to a string for display, but the
table view is actually capable of holding different types of data and
doesn't change the type that it's holding, so you can't assume that
the object it holds is a string. Now, if you are giving the table
strings, then by all means, cast the object to an NSString. If you're
not sure what the type of object you're getting back is, you can find
out in the debugger console by typing
po [returnedValue class]
or adding an NSLog statement to your code like
NSLog(@"returned value class: %@", [returnedValue class]);
HTH
_______________________________________________
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