-2

这是我尝试将一些字符串值写入项目同一文件夹中的 database.plist 文件的代码。因此我不能使用 NSDocumentDirectory。这段代码没有给我任何错误。但是字符串值没有保存在我的 plist 文件数组中。

  -(void)dataFetching
{
NSMutableDictionary *categoryList = [[NSMutableDictionary alloc] initWithContentsOfFile:@"database.plist"];
NSMutableArray *array =(NSMutableArray *) [categoryList valueForKey:@"Saved"];

NSString *testStr = @"test String";

int lastItemIndex = [array count];
[array insertObject:testStr atIndex:lastItemIndex];

[categoryList writeToFile:@"database.plist" atomically:YES];

}
4

1 回答 1

1

In your code the issue is you are not writing an array. And also make sure that before writing to plist your data format should be proper. So try like this:-

[array writeToFile:@"database.plist" atomically:YES];
于 2013-10-26T18:36:21.190 回答