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!



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. :)

Take care,
Guy


On 28-Sep-07, at 8:04 PM, Guy English wrote:


Hi all,

Eric makes a good point - what you're doing with JSON has already been done albeit with a different target format: property lists. I'd just steal the idea. Stealing has a couple of benefits:
a) you don't need to spend the time thinking about how best to do something
b) no one else who uses your code needs to spend the time figuring out why you chose to do it the way you did.


With that in mind here's what I'd do:

This class does all the work.
MyJSONSerialization
- (id) JSONRepresentationForObject: (id) object;
- (id) objectFromJSONRepresentation: (id) jsonRepresentation;

Categories on NSString, NSDictionary, NSArray, etc
- (id) string




_______________________________________________

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>)



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.