On Wed, Oct 15, 2008 at 6:17 PM, Melissa J. Turner <[EMAIL PROTECTED]> wrote:
> It's generally unwise to do this kind of thing if you're dealing with class
> clusters or bridged classes (which category includes both NSString and
> NSNumber). The class you actually get may not be what you're expecting.

This is the case with all classes, not just the ones you mention.
Something as simple as using Key-Value Observing on an object can
change its class to a subclass of the original, causing direct
equality comparisons to fail.

If you can, avoid class comparisons altogether. There are usually
better techniques available which take advantage of the dynamism of
the language. (For example, defining the same method on all the
classes you will process, and having that method do something
different in each class, as you need.) If you cannot avoid class
comparisons, then you must always compare in such a way as to take
subclasses into account. This is just good OO sense: an instance of a
class is also an instance of any superclass of that class, and should
be accepted equally.

Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to