Question: reason: '*-[nscfarray insertobject: atindex:]: mutating method sent to immutable ..

Source: Internet
Author: User

A very small pull-up refresh was very simple and has been done before, but this time there are hundreds of problems, this problem is even more troublesome for nearly a day, as I could not solve this problem, I could not really fall asleep. So I put down my work and gave up my mind carefully. Then I took a hard look at this article and got it done, after reading this article on both sides, you can understand it with a thorough understanding.

The reason is that the variable was assigned a value before, and a variable method cannot be stubbornly assigned to an immutable object.

The original text is excerpted as follows:

Error message :*
Terminating app due to uncaught exception 'nsinternalinconsistencye Xception ', reason :'*  -[Nscfarray insertobject: atindex:]: mutating method sent to immutable object'

The problem occurs in the statement:

[SavearrayAddobject: [nsnumber numberwithint: savenum];

A mutable method is sent to an immutable object.


PS: @ property (nonatomic, retain)
Nsmutablearray *Savearray;

Previously assigned values:

 

Nsmutablearray * Array
= [[Nsmutablearray alloc] init];

Self. savearray=
Array;

[Array release];




Solution:

 

Nsmutablearray * mutaarray
= [[Nsmutablearray alloc] init];

[Mutaarray addobjectsfromarray: savearray];


[Mutaarray Addobject: [nsnumber Numberwithint: savenum];
Self. savearray
= Mutaarray [mutaarray release];


Address: http://blog.sina.com.cn/s/blog_6123f9650101b0zl.html

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.