On 5 Nov 2010, at 9:43 AM, Sherm Pendley wrote:

> What you could do instead is extend NSDictionary with a "convenience
> constructor" class method. Similarly, you could create an instance
> method that would return an instance of your custom class from a
> dictionary.
> 
> @interface NSDictionary (MyWordpressExtensions)
> 
> +(NSDictionary*) dictionaryWithMyCustomObject:(MyCustomObject *)obj;
> - (MyCustomObject *) customObject;
> 
> @end
> 
> True, you'd still need to write the necessary conversion code manually
> - but you'd only need to do so once, and it wouldn't clutter up your
> code outside of these methods. You'd use a different syntax to do the
> conversion, but it would be just as brief and easy to read as your
> proposed type cast. Assuming that you have a "wordpress" object that
> returns an NSDictionary from -getResponse, the type casting you
> propose might look like this:

Would the Key-Value Coding methods dictionaryWithValuesForKeys: and 
setValuesForKeysWithDictionary: help the OP? He's have to deal with boxing and 
unboxing scalar values, and the problem of getting a dictionary with keys the 
object doesn't implement, but it wouldn't take too much luck and care for the 
technique to work for him.

Unless I'm missing something.

        — F

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to