- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在验证空值时,崩溃
-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object
当我使用所有可变类型时。(仅在 iOS 9 中崩溃,Appstore 中我的应用程序的其他版本工作正常)
谁能建议我如何在 null 条件下为键设置值。
NSMutableArray *tempelementsArray=[[NSMutableArray alloc]init];
if(![[catDic objectForKey:@"menuElementList"] isEqual:@""]){
tempelementsArray = [catDic objectForKey:@"menuElementList"];
if(tempelementsArray != nil && [tempelementsArray count]>0)
{
for (NSInteger j=0; j<tempelementsArray.count; j++) {
NSMutableDictionary *elementDic = [[NSMutableDictionary alloc]init];
elementDic = [tempelementsArray objectAtIndex:j];
[elementDic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if ([obj isKindOfClass:[NSNull class]])
{
[elementDic setValue:@"" forKey:key];//App crashes here when one of the value is NULL
}
} ];
}
发生以下崩溃:
*** Terminating app due to uncaught exception NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'
*** First throw call stack:
(
0 CoreFoundation 0x00df3a94 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0051be02 objc_exception_throw + 50
2 CoreFoundation 0x00df39bd +[NSException raise:format:] + 141
3 CoreFoundation 0x00d0ed68 -[__NSCFDictionary setObject:forKey:] + 104
4 Foundation 0x001051ba -[NSMutableDictionary(NSKeyValueCoding) setValue:forKey:] + 68
5 coreDataMenuSample 0x000481d9 __33-[ViewController SaveToCoredata:]_block_invoke188 + 217
6 CoreFoundation 0x00df2849 ____NSDictionaryEnumerate_block_invoke417 + 41
7 CoreFoundation 0x00cd5452 CFBasicHashApply + 130
8 CoreFoundation 0x00d12481 __NSDictionaryEnumerate + 273
9 CoreFoundation 0x00d122ed -[NSDictionary enumerateKeysAndObjectsWithOptions:usingBlock:] + 45
10 CoreFoundation 0x00d12235 -[NSDictionary enumerateKeysAndObjectsUsingBlock:] + 53
11 coreDataMenuSample 0x00043e71 -[ViewController SaveToCoredata:] + 6481
12 coreDataMenuSample 0x0004239d -[ViewController viewDidLoad] + 893
13 UIKit 0x0133fd74 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
14 UIKit 0x013448c2 -[UIViewController loadViewIfRequired] + 1556
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我什至检查过这个类似的问题Strange “mutating method sent to immutable object” error when adding an object to a mutable array
Saving CLLocation error: Mutating method sent to immutable object
最佳答案
看你的代码,我觉得是这一行有问题
NSMutableDictionary *elementDic = [[NSMutableDictionary alloc]init];
elementDic = [tempelementsArray objectAtIndex:j];
tempelementsArray
包含 NSDictionary
而不是 NSMutableDictionary
的实例。更改此代码将有助于:
NSMutableDictionary *elementDic = [[NSMutableDictionary alloc]initWithDictionary:tempelementsArray[j]];
关于ios - 应用程序在 [__NSCFDictionary setObject :forKey:] in iOS 9 only 处崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33365064/
救命!我已经为这个问题苦恼了 1 个小时了。 我正在我的 .h 文件中创建一个数组 @interface LeftMenuViewController : UIViewController
我正在开发 iOS 应用程序。在一种情况下,我正在像这样向服务器发送电话号码和一些短信 - (void)postData:(NSString *)message :(NSString *)mobile
我在从 Web 服务获取的 UITableView 中显示数据。在尝试将此数据添加到 UITableView 时,我遇到了一些奇怪的崩溃 Terminating app due to uncaught
我使用 UIWebView 加载此站点 http://www.xiami.com/song/1024665 如果我触摸此站点中的 View 或播放音频,有时我的应用程序会崩溃,而有时却不会,为什么?
在 JSON 解析期间(使用 AFNetwork json getter 完成),我有以下代码片段: if (![[data class] isKindOfClass:[NSDictionary cl
当此代码在新安装的应用程序上运行时,它工作得很好。但是,当设备上之前没有保存任何数据时,此功能会导致应用程序崩溃。 我收到错误无法将类型 __NSCFDictionary 的值转换为 NSData 并
我有在 iphone 4 上运行的 ios 7 应用程序。我有一个奇怪的问题,由于标题中的错误,应用程序在 for 循环内崩溃。我检查了 SO,它说当您更改要迭代的对象时会发生错误。所以我复制了我用来
我的应用程序有时会出现此错误。我打印了对象并得到了这个: (lldb) po 0x15a2fae0 { "0x15d8bcd0.posErrorMarker{id: 4558}" = ;
我将使用 github Facebook iOS SDK 提供的开源库构建一个支持 Facebook 分享按钮的应用程序。 我的问题是,当我按下按钮时,应用程序崩溃,并且出现此错误: 2012-03-
我正在使用json-famework available on github 。我在我的项目中添加了该项目的引用,在我的 viewController 中添加了 header 搜索路径并导入了 JSO
我正在尝试更新 NSMutableDictionary 但我得到了 mutating method sent to immutable object 错误。 itemMutableArray 是 NS
我使用一个教程将我的 Twitter 主页包含在我的代码中,但对我来说不起作用。 这是代码 @implementation VSViewController - (void)viewDidL
我正在从我的 json 文件中读取 jason 数据,并且我成功打印了 NSarray 类型 arraytsik,现在当我尝试使用 enumerateObjectsUsingBlock 循环遍历 ar
在验证空值时,崩溃 -[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object 当我使用所有可变类型
我正在制作转换器应用程序。我想保存转换历史记录。我看到了this教程,它工作正常,但当我尝试在我的应用程序上使用它时,我收到了 SIGABRT。 Could not cast value of typ
-(id)init{ if (self==[super init]) { NSMutableArray *listname = [[NSMutableAr
此代码导致错误,可能是什么问题? 我读过一些关于锁的东西,不可变对象(immutable对象)在多个线程上使用时很容易崩溃。但我真的不知道那是怎么回事...... -(void)cleanUpAllH
我是 xcode 新手,我遇到了这个问题,当我尝试点击进入 DetailViewcontroller 的单元格并出现错误时,应用程序崩溃并给出此错误:* 由于未捕获的异常而终止应用程序' NSInva
我遵循 getting started 中的每一步使用适用于 ios 的谷歌地图,我做的一切都很好,但在我尝试的每个示例中,模拟器开始询问我是否要打开 GPS,之后,它会抛出错误: 2013-03-0
运行以下代码时,[dict setValue:@"null"forKey:@"name"]; 一直崩溃。我在这里搜索,发现其他帖子是由不使用 NSMutableDictionary 的人引起的。但是我
我是一名优秀的程序员,十分优秀!