Re: KVG generic enough?
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