When I was working today, I encountered such a problem ..
It's so careless. Mark,
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:
(0x2859deb 0x36b96 0x18610ef 0x6c8df 0xabd61 0xac0f8 0x1bc3b 00000x1888765 0x27ddf3f 0x27dd96f 0x2800734 then 00000000000000000x2d5d 0x2551725 0x1)
Libc ++ abi. dylib: terminate called throwing an exception
Program ended with exit code: 0
This is the error code.
NSDictionary *jsonData = [resultDic objectAtIndex:i]; NSArray *eachLines = [[jsonData objectForKey:@"newsTime"] componentsSeparatedByString:@"."]; [jsonData setValue:[eachLines objectAtIndex:0] forKey:@"newsTime"]; [testArr addObject:jsonData];
... It's embarrassing to think about it now.
See reason: The following exception description: it means that a method corresponding to a variable is called by a non-variable.
Mutating method (the method corresponding to the variable): it is the method of the variables that can be changed after creation, such as NSMutableArray and NSMutableDictionary.
Immutable object (unchangeable variables): variables that cannot be changed after being created, such as NSArray NSDictionary.
After modification, it runs normally.
NSMutableDictionary *jsonData = [resultDic objectAtIndex:i]; NSArray *eachLines = [[jsonData objectForKey:@"newsTime"] componentsSeparatedByString:@"."]; [jsonData setValue:[eachLines objectAtIndex:0] forKey:@"newsTime"]; [testArr addObject:jsonData];
On the way to learning, I will share with you.