Saving a Property List in a File Wrapper
·1 min
Saving a property list in a file wrapper takes two steps. First, call NSPropertyListSerialization’s dataFromPropertyList: or dataWithPropertyList: methods to create a property list. The dataWithPropertyList: method was introduced in Mac OS X 10.6. Use dataFromPropertyList: if you are supporting earlier versions of Mac OS X.
NSMutableDictionary* root; NSError* error; NSData* propertyList = [NSPropertyListSerialization dataWithPropertyList:root format:NSPropertyListXMLFormat_v1_0 options:0 error:&error];
Second, pass the property list you created as the first argument to NSFileWrapper’s addRegularFileWithContents: method.
NSFileWrapper* wrapper; [wrapper addRegularFileWithContents:propertyList preferredFilename:@"MyFile.plist"];
My Working with Cocoa File Packages post has detailed information on file packages. Read Apple’s Property List Programming Guide for more information on property lists.