How to insert object already existing objects in NSMutableArray list

我的梦境 提交于 2020-01-06 19:57:11

问题


I am getting a problem, while inserting an object into the main List.

[editContactList addObject:editcontacts];
[editObject.contactList insertObject:editContactList atIndex:0];//error as mutating method sent to immutable object
[editcontacts release];

回答1:


If you get that particular error, you don't actually have an NSMutableArray; you have an NSArray. Which is immutable. (Note that simply casting an NSArray to NSMutableArray does nothing, the array itself needs to be an instance of a mutable array, rarely seen with instance variables, especially those made accessible publicly.)

Edit: We're going to need some more information; how are these variables defined, how are they initialized, etc.



来源:https://stackoverflow.com/questions/2712126/how-to-insert-object-already-existing-objects-in-nsmutablearray-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!