NSDictionary *dict = [NSDictionary dictionaryWithObject:string forKey:keyString];
NSMutableArray *returnArray = [self returnAllEntriesInformationforkey:keyString];
if (![returnArray containsObject:string]){
[self.newDataArray addObject:dict];
}
[[NSUserDefaults standardUserDefaults] setObject:[self.newDataArray copy] forKey:@"Datanew"];
[[NSUserDefaults standardUserDefaults] synchronize];
上面的代码在Mavericks和Lower中运行得非常好,但是在Yosemite和El Capitan中,它没有将数据添加到默认plist中的“Datanew”数组键。
我尝试使用下面的代码而不是做一个数组的副本也没有运气:
[[NSUserDefaults standardUserDefaults] setObject:self.newDataArray forKey:@"Datanew"];
如果我在代码中添加一个测试,就会创建关键的Cheese,并将“我喜欢的奶酪”添加到plist中,但数组数据不会添加到Datanew键 - 我将重复它在Mavericks和下面 - 任何想法为什么?
NSDictionary *dict = [NSDictionary dictionaryWithObject:string forKey:keyString];
NSMutableArray *returnArray = [self returnAllEntriesInformationforkey:keyString];
if (![returnArray containsObject:string]){
[self.newDataArray addObject:dict];
}
[[NSUserDefaults standardUserDefaults] setObject:[self.newDataArray copy] forKey:@"Datanew"];
[[NSUserDefaults standardUserDefaults] setObject:@"I Like Cheese" forKey:@"Cheese"];
[[NSUserDefaults standardUserDefaults] synchronize];
数组中的数据用于自动填充,数组中的数据最初是从plist中的Datanew键读取的,稍后在用户填写数据时添加数据。如果我将数组的内容输出到控制台这里显示的是 - 问题不在于数据,即使有新的条目也不会保存。
08/10/2015 20:21:20.449 MyApp[12981]: array data (
{
mail = "myemail@gmail.com";
},
{
mail = "test@test.co.uk";
},
{
mail = "test@gmail.com";
},
{
username = myusername;
},
{
first = "Latest News";
},
{
"post_title" = Example;
},
{
first = "Information is here";
},
{
"ctl00$pagecontent$ctlxlayouttime" = "0:30";
},
{
first = Adam;
},
{
q = "google search";
},
{
"post_title" = Facts;
},
{
mail = testtest;
}
)