Re: What is an id?
Re: What is an id?
- Subject: Re: What is an id?
- From: Andrew Merenbach <email@hidden>
- Date: Thu, 22 May 2008 10:21:19 -0700
Not that I want to respond to myself, but I want to correct:
You'll "get a warning" if an action call is not implemented by NSObject.
Sorry for the confusion!
Also, I want to state that I do feel that id is a very useful thing,
despite how my first paragraph below makes it sound. But that's just
my own opinion.
Cheers,
Andrew
On May 22, 2008, at 10:16 AM, Andrew Merenbach wrote:
Hi, John,
There have been discussions on this list in the past, some of which
might (or might not!) be helpful. Some, IIRC, lapsed into debate as
to whether the "id" concept (a) was a bad idea, (b) was useless, (c)
was confusing, or (d) made things difficult. Basically, "id" isn't
exactly a type -- just a typedef. In objc.h:
typedef struct objc_class *Class;
typedef struct objc_object {
Class isa;
} *id;
So it's basically a typedef for an Objective-C object. It's *not*,
however, "equivalent" entirely to, say using NSObject *, since if
NSObject doesn't implement a method, you'll get a warning. For
instance:
id del = [NSApp delegate];
[del myAction];
is not the same as:
NSObject *del = [NSApp delegate];
[del myAction];
As long (IIRC) as you #import your application delegate's header (in
this example) into the .m file that contains the first two lines of
above code, the compiler will say, "well, there's a method of this
name -- perhaps this id refers to it. I won't throw a warning!"
With the NSObject version, however, you'll absolutely get a
warning. Also, I believe that the id typedef can also point to
objects that are *not* descendants of NSObject, which may or may not
be of relevance to you, but is a good point, IMHO.
There are other advantages, IIRC, and possibly some disadvantage,
but I can't think of them off the top of my head.
Hope this helps!
Cheers,
Andrew
On May 22, 2008, at 10:05 AM, john darnell wrote:
Okay, this is a really basic question, but I need some help
figuring out
what the code wants.
In the documentation for NSTableView, I am told that I must
implement as
part of a datasource the following function:
- (id) tableView:(NSTableView *) aTableView
objectValueForTableColumn: (NSTableColumn *) aTableColumn
row: (int) row
{
/* some code here */
return id;
}
The question is, what does the code want me returning as an id?
I tried to do a search in Cocoa Help on id and as you might
imagine, I
got lots and lots of hits, none of which looked anywhere near what I
wanted for an explanation of what id is. So what is the framework
expecting me to return?
R,
John A.M. Darnell
Team Leader
Walsworth Publishing Company
Brookfield, MO
John may also be reached at email@hidden
Trivia Question: In SciFi Channel's hit series, FARSCAPE, who played
the voice of Pilot?
Answer: The voice of Pilot was played by Lani Tupu, the same actor
who
played the villain-turned-refugee, Crais.
_______________________________________________
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
_______________________________________________
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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