开发者

iPhone - Populating an array with the content of compressed plist file

Let's say I have a plist file, and I want to compress it. I have a method that loads this compressed file, uncompress it, and put the result into a NSString.

How may I convert that NSString into an array as simple as it开发者_如何学JAVA can be done with those lines when the plist is not compressed :

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];
NSArray* arrayOfDatas = [NSArray arrayWithContentsOfFile:filePath];


Read the file into an NSData then use:

+ (id)propertyListWithData:(NSData *)data options:(NSPropertyListReadOptions)opt format:(NSPropertyListFormat *)format error:(NSError **)error

where NSPropertyListFormat is NSPropertyListBinaryFormat_v1_0

Creating to NSData to write out is:

+ (NSData *)dataWithPropertyList:(id)plist format:(NSPropertyListFormat)format options:(NSPropertyListWriteOptions)opt error:(NSError **)error

Example (not tested):

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];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜