Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: name that method!



Hi Guy,

Thank you for this detailed post. I find that it is a little bit complicated for what I need right now, but I may go back and rework it along the lines you suggest in the future should my needs change. There's no reason why I couldn't keep backwards compatibility.

Stig

On 29 Sep 2007, at 01:20, Guy English wrote:

heh ... oops. Turns out the hotkey for send in Mail is the same hotkey for Open Quickly in Xcode ... make sure you switch focus first!

Anyway:

Categories on NSString, NSDictionary, NSArray, etc
- (id) stringFromJSONRepresentation: (id) jsonRep;
- (id) dictionaryFromJSONRepresentation: (id) jsonRep;
- (id) arrayFromJSONRepresentation: (id) jsonRep;

For Mutable subclasses of the above just call the immutable version then return an autoreleased mutable copy.

These just call into MyJSONRepresentation and check that the class returned from - (id) objectFromJSONRepresentation is the right one.

Additionally on NSSString, since it's just convenient and matches the plist stuff, I'd add:

- (id) objectFromJSONRepresentation;

You may want to add the mutability options that NSPropertyList does if you require that.

Anyway I think that'll work well because people will be used to the pattern, all your JSON code ends in one place (MyJSONSerialization) and you can put the code for the categories on string, dictionary and array in there too.

So that's my advice. This is very much bike shed territory though - everyone's going to have an opinion on how to do it best. :)

Paint it green! ;)

--
http://code.brautaset.org
http://blog.brautaset.org


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: name that method! (From: Erik Buck <email@hidden>)
 >Re: name that method! (From: Guy English <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.