Formats for communication between backend and Objective-C / Cocoa

I am developing an application for iPhone connected to a server. He must communicate with him many times, for several requests. I am sending HTTP messages, but I want to get more complex responses that I can somehow analyze. Presumably, I can provide any type of response format from the server, so my question is: which one will be easier (perhaps even faster) to use / disassemble for Objective-C / Cocoa and convert some view to a dictionary?

I know this is a bit subjective, but I still think this is the right question, some programming languages ​​have more support for some formats and less for others.

+3
source share
3 answers

In the long run, Cocoa's easiest format is a list of properties , since Cocoa can parse it natively in a dictionary or array.

You can use NSDictionary +dictionaryWithContentsOfFile:and +dictionaryWithContentsOfUrl:read plist file in the dictionary.

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

+2
source

PList is a good answer and very useful, but many server-side users will be more comfortable creating JSON - TouchJSON is a very good JSON parser for iPhone.

+2
source

While there plist gem for ruby , the JSON or (raw) XML much more popular outside the Apple world. For example, most JavaScript libraries are configured to use one or both of them.

So, if you are talking exclusively with iPhone, plist is probably a good choice, but otherwise you should consider using JSON (or XML).

+1
source

Source: https://habr.com/ru/post/1729610/


All Articles