如何将对象已存在的对象插入NSMutableArray列表中 [英] How to insert object already existing objects in NSMutableArray list
问题描述
在将对象插入主列表时遇到问题.
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];
推荐答案
如果遇到该特定错误,则实际上没有NSMutableArray
;您有一个NSArray
.这是一成不变的. (请注意,简单地将NSArray
强制转换为NSMutableArray
并没有任何作用,数组本身必须是可变数组的实例,在实例变量中很少见,尤其是那些可以公开访问的实例变量.)
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.)
编辑:我们将需要更多信息;这些变量的定义方式,初始化方式等.
We're going to need some more information; how are these variables defined, how are they initialized, etc.
这篇关于如何将对象已存在的对象插入NSMutableArray列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!