• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: name that method!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: name that method!


  • Subject: Re: name that method!
  • From: Guy English <email@hidden>
  • Date: Fri, 28 Sep 2007 20:20:36 -0400

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: name that method!
      • From: Stig Brautaset <email@hidden>
References: 
 >Re: name that method! (From: Erik Buck <email@hidden>)

  • Prev by Date: Re: name that method!
  • Next by Date: AIFF files and Disc Recording
  • Previous by thread: Re: name that method!
  • Next by thread: Re: name that method!
  • Index(es):
    • Date
    • Thread