gpt4 book ai didi

ios - <__NSCFDictionary : 0x1557f400> was mutated while being enumerated.'

转载 作者:行者123 更新时间:2023-11-29 10:24:05 26 4
gpt4 key购买 nike

我有在 iphone 4 上运行的 ios 7 应用程序。我有一个奇怪的问题,由于标题中的错误,应用程序在 for 循环内崩溃。我检查了 SO,它说当您更改要迭代的对象时会发生错误。所以我复制了我用来临时变量的两个变量,但问题仍然存在。第一次迭代完成时出现问题。

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary * badges = [defaults objectForKey:@"badges"];
NSMutableDictionary *newBadges = badges;
for(NSString* key in badges)
{
NSDictionary* badge = [badges objectForKey:key];
if([[badge objectForKey:@"achived"] isEqual: @"NO"])
{
if([self checkBadgeCondition:badge])
{
NSMutableDictionary *tempBadge = [badge mutableCopy];
[self showAlertBadge:badge];
[tempBadge setObject:@"YES" forKey:@"achived"];
[newBadges setObject:tempBadge forKey:[tempBadge objectForKey:@"name"]];
}
}
}

最佳答案

newBadges = badges

这不是副本,它只是对同一事物的另一种引用。您还应该期望来自用户默认值的字典(或数组)是可变的。所以,在这里制作一个可变副本

newBadges = [badges mutableCopy]

关于ios - <__NSCFDictionary : 0x1557f400> was mutated while being enumerated.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33334522/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com