IOS development-mutating method sent to immutable object Error

Source: Internet
Author: User

IOS development-mutating method sent to immutable object Error

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.

 

[Cpp] 
  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];

     

    ... 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.

     

     

    [Cpp]
    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];

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.