• 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 18:26:23 -0400

On Apr 6, 2006, at 11:05 AM, James Bucanek wrote:

As an aside, you *may* have difficulty testing for class membership for primitives like NSArray or NSString. Many of these core classes are implemented as class clusters in the Cocoa framework, so even if you call [NSString stringWithBlah:...] you are not guaranteed to get back a subclass of NSString -- even if the returned object acts, smells, and quacks exactly like an NSString.

While the return type is specified as id, the implied contract is that a subclass of NSString will be returned. If you have a concrete example of where this is not the case, please show us.


As an example, you cannot use isKindOfClass or isMemberOfClass to distinguish betweeen an NSArray and an NSMutableArray (search the Cocoa-Dev archives for the threads), even though the documentation would have you believe that NSMutableArray is a simple subclass of NSArray.

It is true that you can't use isKindOfClass to determine if an NSArray is mutable, but not for this reason. The reasons is that in the current implementation, the concrete subclass returned for an immutable array is the same concrete subclass returned for a mutable array.


I agree that this is counter-intuitive, but in practice it shouldn't pose a problem because you are respecting the contract interfaces and treating an array as immutable or not based on the declared type, not the runtime type, right?

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: 
 >Re: Check the class of a variable? (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: Calling Obj-C Class Methods From Java
  • Next by Date: Webkit and cookies
  • Previous by thread: Re: Check the class of a variable?
  • Next by thread: Re: Check the class of a variable?
  • Index(es):
    • Date
    • Thread