On May 7, 2014, at 12:30 , Carl Hoefs wrote:
For the moment, I'm using only NSStrings and NSNumbers. I'm sending data back and forth between OSX and iOS devices, and NSDictionary is a very convenient container. Once I show that this will work then the pressure will ease off and I'll have time dig into more generalized ways (NSPropertyListSerialization?), ensuring things won't break in the future when requirements and use cases change. I just wasn't prepared going into this for the steep learning curve for what I assumed was a more or less trivial data serialization function. The documentation (which, yes, I have read but still can't make much sense of) documents but doesn't educate very well. I'm still a bit overwhelmed by the sometimes huge generalized mechanisms required to do things the Cocoa way, but I will overcome that with time and effort.-Carl
Hi,If you are going Cocoa to Cocoa, and simple data types, NSPropertyListSerialization should work.
I use it all the time for reading and writing to disk. here's an adaptation... /* transfer out */NSDictionary* dictionaryToTransfer; // <- set this to your input dictionary
NSString* err;NSData* data = [NSPropertyListSerialization dataFromPropertyList:dictionaryToTransfer format:NSPropertyListBinaryFormat_v1_0 // or NSPropertyListXMLFormat_v1_0
errorDescription:&err]; // now send the data /* receive */ NSString* err; NSData* data; // <- set this to your input data from the transferNSDictionary* dictionaryToReceive = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutableformat:NULL // NSPropertyListSerialization determines for itself if the input was as text or as binary.
errorDescription:&err];You can also use the same procedure for any other property-list object (NSArray, NSString, NSNumber, etc.). (Also check for and adapt the newer api's (dataWithPropertyList:format:options:error: for instance) ).
Manoah F. Adams This message is signed with a certificate and-or PGP key. Disregard any unverified messages from this address. ===========
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com