文件讀入到一個NSData
然後使用:
+ (id)propertyListWithData:(NSData *)data options:(NSPropertyListReadOptions)opt format:(NSPropertyListFormat *)format error:(NSError **)error
其中NSPropertyListFormat
爲NSPropertyListBinaryFormat_v1_0
創建於NSData
寫出來就是:
+ (NSData *)dataWithPropertyList:(id)plist format:(NSPropertyListFormat)format options:(NSPropertyListWriteOptions)opt error:(NSError **)error
實施例(未測試):
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSError *error;
NSArray* plist = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:NULL error:&error];
NSData *propertyListSerializedData = [NSPropertyListSerialization dataWithPropertyList:plist format:NSPropertyListBinaryFormat_v1_0 options:0 error:&error];
[propertyListSerializedData writeToFile:filePath atomically:YES];