Re: object type testing
Re: object type testing
- Subject: Re: object type testing
- From: Uli Kusterer <email@hidden>
- Date: Sun, 7 May 2006 20:22:41 +0200
Am 07.05.2006 um 17:41 schrieb Ben Dougall:
regarding finding out if an object instance is a particular type of
class or not
Just to play the party pooper here: Keep in mind that, *in general*
it's a sign of a mistake in your design if you need to check for a
particular class. Especially in Cocoa, it is perfectly fine that an
object may not be of a particular class, but rather of a class that
implements the same methods or a subclass of a particular class. Even
more importantly: NSString and several other fundamental classes of
Foundation are actually class clusters and the class itself is an
abstract base class. So, e.g. checking whether an object is of class
NSString will always return false, because you only get objects of
NSMutableString, NSCFString or whatever...
So, if you can, use conformsToProtocol, respondsToSelector or
similar methods to check for the actual feature you need, and not for
a particular class name.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
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