Hi,
Thats great.
I first learned about this method from Mike Ash's blog post : <https://mikeash.com/pyblog/friday-qa-2013-08-30-model-serialization- with-property-lists.html>.
You will likely many more ideas there.

Cheers!


Manoah F. Adams
federaladamsfamily.com/developer

===========


On May 8, 2014, at 11:15 , Carl Hoefs wrote:

Wonderful! Just what I was looking for!
Thanks!
-Carl

On May 7, 2014, at 3:13 PM, Manoah F. Adams <mhfad...@federaladamsfamily.com> wrote:

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 transfer
NSDictionary* dictionaryToReceive = [NSPropertyListSerialization propertyListFromData:data
                                                
mutabilityOption:NSPropertyListImmutable
format: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.
===========







Attachment: 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

Reply via email to