Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert NSDictionary to NSData as a plist (without saving the dictionary)

Does anyone know how to convert a NSDictionary object into an NSData object as a plist without saving the dictionary first? I would like my iphone app to send an email with a plist containing my dictionary attached. I am currently using skpsmtpmessage, http://code.google.com/p/skpsmtpmessage/, to send email.

Thanks in advance

like image 319
cduck Avatar asked Jan 22 '10 08:01

cduck


3 Answers

You can use NSPropertyListSerialization class for that. Have a look at its method:

+ (NSData *)dataFromPropertyList:(id)plist format:(NSPropertyListFormat)format
                              errorDescription:(NSString **)errorString

Returns an NSData object containing a given property list in a specified format.

like image 99
Vladimir Avatar answered Oct 28 '22 01:10

Vladimir


Use the NSPropertyListSerialization class. The Dev Centre tutorial on Archives has a section on Serializing Objects which covers this.

like image 22
Robert Christie Avatar answered Oct 28 '22 01:10

Robert Christie


As of iOS 4.0, you should now be using the newer method below:

+ (NSData *)dataWithPropertyList:(id)plist format:(NSPropertyListFormat)format options:(NSPropertyListWriteOptions)opt error:(NSError **)error
like image 21
Owain Hunt Avatar answered Oct 28 '22 03:10

Owain Hunt