【发布时间】:2011-08-02 03:15:12
【问题描述】:
我正在尝试将 NSMutableArray 存储到 pList 中,但是当我检查我的 data.pList 时,里面没有任何值。知道为什么吗?
-(void)run
{
Global *myGlobal = [Global sharedGlobal];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"];
NSMutableDictionary *category = [[NSMutableDictionary alloc]init];
NSMutableDictionary *totalCategory = [[NSMutableDictionary alloc]init];
for (int i = 0 ; i < [myGlobal.categoryArray count];i++){
Category * c = [categoryArray objectAtIndex:i];
[category setObject:c.name forKey:@"category"];
[totalCategory setObject:category forKey:@"allCategory"];
NSMutableDictionary *stock = [NSMutableDictionary dictionaryWithContentsOfFile:path];
[stock writeToFile:path atomically:YES];
}
if( totalCategory==nil ){
NSLog(@"failed to retrieve dictionary from disk");
}
}
【问题讨论】: