• 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: KVG generic enough?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVG generic enough?


  • Subject: Re: KVG generic enough?
  • From: Graham Cox <email@hidden>
  • Date: Thu, 19 Jul 2012 00:22:47 +1000

On 18/07/2012, at 11:08 PM, William Squires wrote:

> How can I determine what I get back? (i.e. what does the id pointer point to? an NSString? an NSNumber? NSDecimalNumber? NSData? another NSObject subclass?)


Others have told you about -isKindOfClass, but I think you are incorrect in thinking you even need it.

If you ask for a property by name, you already know its type. It's no different than using the accessor. If you don't know its name, you can't ask for its value, so the type is irrelevant.

Where the anonymity is a benefit is when you need to drive a UI from a data model. Most UI controls take an "object" value, which is typed id. By using -valueForKey: and then -setObjectValue:, your code doesn't need to know the type - it just passes the value as a black box of some kind. This is how bindings works, which eliminates even that bit of glue.

Properties are not conceptually any different from a dictionary. If you ask a dictionary to return an object for a given key, you know its type by contract, not by inspection.

--Graham


_______________________________________________

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

  • Follow-Ups:
    • Re: KVG generic enough?
      • From: Alex Zavatone <email@hidden>
References: 
 >KVG generic enough? (From: William Squires <email@hidden>)

  • Prev by Date: Re: do you init your instance variables in init method or outside the class?
  • Next by Date: Re: do you init your instance variables in init method or outside the class?
  • Previous by thread: Re: KVG generic enough?
  • Next by thread: Re: KVG generic enough?
  • Index(es):
    • Date
    • Thread