当前位置:   article > 正文

iOS开发-mutating method sent to immutable object错误_ios mutating method sent 他inmutable object

ios mutating method sent 他inmutable object

今天干活的时候,遇到了这样一个问题..

实在是太粗心了。mark下,

2014-01-05 11:44:34.762 softwareApp[1435:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[JKDictionary setObject:forKey:]: mutating method sent to immutable object'

*** First throw call stack:

(0x285a012 0x1e48e7e 0x2859deb 0x36b96 0x18610ef 0x6c8df 0xabd61 0xac0f8 0x1e5c6b0 0x1bc3b 0x1e5c6b0 0x1888765 0x27ddf3f 0x27dd96f 0x2800734 0x27fff44 0x27ffe1b 0x2a927e3 0x2a92668 0xd8cffc 0x2d5d 0x2551725 0x1)

libc++abi.dylib: terminate called throwing an exception

Program ended with exit code: 0


这是报错处的代码。

  1. NSDictionary *jsonData = [resultDic objectAtIndex:i];
  2. NSArray *eachLines = [[jsonData objectForKey:@"newsTime"] componentsSeparatedByString:@"."];
  3. [jsonData setValue:[eachLines objectAtIndex:0] forKey:@"newsTime"];
  4. [testArr addObject:jsonData];


…现在想想都觉得丢人阿。

看reason:后面的异常说明:意思是我把一个可变量对应的方法让一个不可变量来调用

mutating method(可变量对应的方法):是那些在创建后可以被更改的变量所拥有的method,比如NSMutableArray,NSMutableDictionary 等

immutable object(不可改变的变量):就是那些被创建后不能被改变的变量:比如 NSArray NSDictionary等


修改后,正常运行。

  1. NSMutableDictionary *jsonData = [resultDic objectAtIndex:i];
  2. NSArray *eachLines = [[jsonData objectForKey:@"newsTime"] componentsSeparatedByString:@"."];
  3. [jsonData setValue:[eachLines objectAtIndex:0] forKey:@"newsTime"];
  4. [testArr addObject:jsonData];



学习的路上,与君共勉。


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/248409
推荐阅读
相关标签
  

闽ICP备14008679号