• 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: Check the class of a variable?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Check the class of a variable? (From: d2kagw <email@hidden>)

  • Prev by Date: Re: Check the class of a variable?
  • Next by Date: Re: Check the class of a variable?
  • Previous by thread: Re: Check the class of a variable?
  • Next by thread: Re: Check the class of a variable?
  • Index(es):
    • Date
    • Thread