• 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: Comparing the Class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing the Class


  • Subject: Re: Comparing the Class
  • From: "Michael Ash" <email@hidden>
  • Date: Wed, 15 Oct 2008 22:22:31 -0400

On Wed, Oct 15, 2008 at 6:17 PM, Melissa J. Turner <email@hidden> 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 (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

References: 
 >Comparing the Class (From: Ruotger Skupin <email@hidden>)
 >Re: Comparing the Class (From: "Melissa J. Turner" <email@hidden>)

  • Prev by Date: Re: -[NSGarbageCollection disableCollectorForPointer:] ?
  • Next by Date: Re: how to complete c/s app
  • Previous by thread: Re: Comparing the Class
  • Next by thread: Re: Comparing the Class
  • Index(es):
    • Date
    • Thread