Re: NSDictionary casting
Re: NSDictionary casting
- Subject: Re: NSDictionary casting
- From: Fritz Anderson <email@hidden>
- Date: Fri, 5 Nov 2010 11:53:30 -0500
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 (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