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
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.
Use the NSPropertyListSerialization class. The Dev Centre tutorial on Archives has a section on Serializing Objects which covers this.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With