我想存儲一個NSMutableArray到一個pList,但是當我檢查我的data.plist,裏面沒有任何值。任何想法爲什麼?保存NSMutableArrays 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");
}
}
一個例子是不是? –
是真實的,但您需要將某物放入'stock'或writeToFile將不存儲任何東西。 – progrmr