views:

247

answers:

3

I'm developing an iPhone app that is connected to a backend server. It needs to communicate with it many times, through several requests. I'm sending HTTP messages, but I want to receive more complex responses that I can parse somehow. Supposedly, I can provide any type of format for responses from the server, so my question is: which one would be easier(maybe even faster) to use/parse for Objective-C/Cocoa, and transform in a dictionary of some kind?

I know it's a bit subjective but I still think it's a valid question, some programming languages just have more support for some formats and less for others.

+2  A: 

From Cocoa 's perspective, the simplest format is a property list as Cocoa can parse this natively into a dictionary or an array.

You can use NSDictionary's +dictionaryWithContentsOfFile: and +dictionaryWithContentsOfUrl: to read a plist file into a dictionary.

If your plist data is not in a file, you can also convert an NSData object containing plist data to a dictionary with +[NSPropertyListSerialization dataFromPropertyList:format:errorDescription:] or convert an NSString to a dictionary with -[NSString propertyList].

Ole Begemann
Mr-sk
OK, sounds pretty cool on a first look. But so far I haven't understood what to do in my specific scenario. I have the XML already on my side (Obj-C), in a NSString. Let's assume it also has the plist convension. How to I convert that plist-xml-string to a dictionary?
treznik
I have added some more info to my answer. This info is also available in the Property List Programming Guide I linked to above.
Ole Begemann
+2  A: 

PList is a good answer and very usable, but many server side people will be more comfortable producing JSON - TouchJSON is a very good JSON parser for the iPhone.

Kendall Helmstetter Gelner
+1  A: 

While there is a plist gem for ruby, JSON or (raw) XML are much more popular outside the Apple world. For instance most JavaScript libraries are set up to speak one or both of these.

So if you're exclusively talking to an iPhone, the plist is probably a good choice, but otherwise you should consider using JSON (or XML).

Frank Schmitt