plist的根Type只能是字典(NSDictionary)或者是数组(NSArray)因此归档时咱们只能将数组或字典保存到plist文件中,可是NSString也能经过归档保存到plist文件中同时它也能够经过stringWithContentsOfFile解档,它保存到plist中时Type是空的,Value是有值的!数组
NSArray *arr = [[NSArray alloc] initWithObjects:@"1", @"2", nil]; // NSDocumentDirectory 要查找的文件 // NSUserDomainMask 表明从用户文件夹下找 // 在iOS中,只有一个目录跟传入的参数匹配,因此这个集合里面只有一个元素 NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; NSString *filePath = [path stringByAppendingPathComponent:@"xxx.plist"]; [arr writeToFile:filePath atomically:YES];
NSString *filePath = [path stringByAppendingPathComponent:@"xxx.plist"]; // 解档 NSArray *arr = [NSArray arrayWithContentsOfFile:filePath]; NSLog(@"%@", arr);