• 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: KVO and isKindOfClass:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO and isKindOfClass:


  • Subject: Re: KVO and isKindOfClass:
  • From: "Timothy J.Wood" <email@hidden>
  • Date: Thu, 17 Mar 2005 13:16:40 -0800


On Mar 17, 2005, at 12:51 PM, patrick machielse wrote:
Never realized this, but couldn't you just use

	if (![otherObject isKindOfClass:[self class]])

so you compare to the class of the 'clone'?
Seems better to not have the class's name hard wired too.

That won't work either. 'otherObject' might be of MyClass and self might be of NSNotifying_MyClass, and with the two classes being peers this will fail.


Also, note that using [self class] is fragile in a different way than hard-coding the class. If you have a subclass of MyClass, then your -isEqual: would start returning "is equal as far as the common superclass is concerned" instead of "is equal". Also, using [self class] here will cause you to start getting [A isEqual:B] != [B isEqual:A] when A is an instance of a subclass of B's class. Equality is typically expected to be symmetric.

Another school of thought would be to use [self class] == [otherObject class], but that has problems of its own (and would also break due to this KVO bug :)


-tim

_______________________________________________
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: 
 >Re: KVO and isKindOfClass: (From: patrick machielse <email@hidden>)

  • Prev by Date: [OT] Looking for a rare bird (job offer)
  • Next by Date: Re: KVO and isKindOfClass:
  • Previous by thread: Re: KVO and isKindOfClass:
  • Next by thread: [OT] Looking for a rare bird (job offer)
  • Index(es):
    • Date
    • Thread