Re: Check the class of a variable?
Re: Check the class of a variable?
- Subject: Re: Check the class of a variable?
- From: Jim Correia <email@hidden>
- Date: Thu, 6 Apr 2006 09:33:15 -0400
On Apr 6, 2006, at 9:24 AM, d2kagw wrote:
Hey there all..
Just wondering if theres a easy way of checking the class of a
variable...
I've gotten this far:
if ( [[theChildren objectForKey:@"data"] class] == @"NSCFArray" )
{
// do something
}
The -class message doesn't return a string, it returns a Class.
You probably don't want to check to see if it is particular class,
but if it is that kind of object, or any subclass of that object.
if ([obj isKindOfClass: [NSArray class]]) {
// do something
}
And in some cases, you really don't care if an object is a particular
class, just if it can respond to the message you want to send it:
if ([obj respondsToSelector: @selector(foobazzle:)]) {
[obj foobazzle: arg];
}
Jim
_______________________________________________
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