On Jul 11, 2012, at 4:54 PM, Keary Suska wrote: > On Jul 11, 2012, at 2:45 PM, Motti Shneor wrote: >> Of what I read from everyone, and after examining the suggested code from >> Jens Alfke, I think I'm inclined to something simpler, hinted by Keary >> Suska. Could you spare a few more words on the "undefinedKey" override? > > I would create a base class that implements -valueForUndefinedKey: and > -setValue:forUndefinedKey: (per the doc links that another poster provided). > These methods would simply get/set from the dictionary. The only thing that > requires a little consideration is how you may choose to validate the key (if > at all)--i.e. determine whether you want to throw an exception for unknown > keys. You can throw by simply calling super's implementation. To validate you > could keep an array of valid key names (somewhat fragile, as you need to keep > it updated), or use runtime inspection functions (see: > https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/doc/uid/TP40008048-CH101-SW24). > More cryptic but not fragile.
I'm probably missing something, but why bother with the undefinedKey methods? Why not just override -setValue:forKey: and -valueForKey:? Dave _______________________________________________ Cocoa-dev mailing list ([email protected]) 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 [email protected]
