【发布时间】:2014-05-22 10:18:35
【问题描述】:
你好,我有这样的功能
- (void)save{
NSLog(@" %@ %@ %@ %@",AppAddressLine,AppCustomerName,AppPhoneNumber,AppPriceTier);
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentsDirectory = [paths objectAtIndex:0];
path = [documentsDirectory stringByAppendingPathComponent:@"NewInAppCustomer.plist"];
NSMutableArray *MainRoot=[[NSMutableArray alloc]initWithContentsOfFile:path];
NSMutableDictionary *ContentDictionary=[[NSMutableDictionary alloc]init];
[ContentDictionary setValue:AppCustomerName forKey:@"CustomerName"];
[ContentDictionary setValue:AppAddressLine forKey:@"CustomerAddress"];
[ContentDictionary setValue:AppPhoneNumber forKey:@"CustomerPhoneNumber"];
[ContentDictionary setValue:AppPriceTier forKey:@"CustomerPriceTier"];
[MainRoot addObject:ContentDictionary];
[MainRoot writeToFile:path atomically:YES];
NSLog(@"%@",MainRoot);
}
当我打印时
NSLog(@" %@ %@ %@ %@",AppAddressLine,AppCustomerName,AppPhoneNumber,AppPriceTier);
它显示一个正确的值,
但是这一行
NSLog(@"%@",MainRoot);
将nil 显示为其值。
谁能给我解释一下?
【问题讨论】:
-
检查文件是否存在
-
另外,你的 plist 是数组还是字典?
-
我刚刚通过编程方式创建了该 plist
标签: ios objective-c nsmutablearray plist nsmutabledictionary