开发者

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? 开发者_如何学CI 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜