A little bit of knowledge about variable arrays and small knowledge about variable Arrays

Source: Internet
Author: User

A little bit of knowledge about variable arrays and small knowledge about variable Arrays

Recently, an error occurred while using the variable array of iOS. The error message is:

Reason: '-[_ NSCFArray removeObjectAtIndex:]: mutating method sent to immutable Object'

The literal meaning is that the variable array method is sent to an immutable object.

The declaration and initialization Code are as follows:

// Declare NSMutableArray * dataArray; // initialize dataArray = [NSMutableArray array];

By analyzing dataArray, we found that dataArray is assigned a value only after the data is requested from the server. The problem is that it should appear here.

[manager POST:requestUrl       parameters:jsonDictionary          success:^(AFHTTPRequestOperation *operation, id responseObject) {              NSLog(@"json: %@", responseObject);                            dataArray = responseObject;                            [self.tableView reloadData];                        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {              NSLog(@"%@", error);                                      }];

Therefore, the problem should be that the returned value of responseObject is an immutable array. After the value is assigned, dataArray also becomes an immutable array.

If you want to continue using it, do some processing, for example:

dataArray = [NSMutableArray arrayWithArray:dataArray];

 

 

Reference: http://stackoverflow.com/questions/22381384/ios-error-nscfarray-removeobjectatindex-mutating-method-sent-to-immutable

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.