views:

118

answers:

1

I have an application where a user creates settings that are stored in an NSMutableDictionary. I have to send this to a server, where it can be later retrieved by a recipient.

I can serialize the dictionary, and send it to the server. My question is, if I send it as NSData, store it in a blob field in my postgresql db, and then send it back when requested, is it as simple as using [NSDictionary initWithContentsOfURL]? Is there anything I need to worry about on the server side? http headers sending and receiving?

If I send it as NSDictionary -> serializedData -> xml, so that other devices than iPhones can use it, is there a simple way to recreate the NSDictionary from the xml, or should I store both xml and data, and send the one requested?

+2  A: 

Just to be safe, I'd serialize it as a text plist. That's an xml format, so it should be usable anywhere, but is also convertible back to an NSDictionary with one call.

Use -[NSPropertyListSerialization dataFromPropertyList:format:errorDescription:], with NSPropertyListXMLFormat_v1_0 as the format.

Ben Gottlieb
Yep, that works beautifully.The single call is + (id)propertyListFromData:(NSData *)data mutabilityOption:(NSPropertyListMutabilityOptions)opt format:(NSPropertyListFormat *)format errorDescription:(NSString **)errorStringfor those interested.
Dan Donaldson