On Jul 18, 2012, at 10:22 AM, Graham Cox wrote: > > 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.
How do you automatically know its type if you know its name? I'm interested to understand the "why" of that statement. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com