How do you change the elements within an NSArray?

前端 未结 3 1997
一整个雨季
一整个雨季 2021-01-03 07:48

I am a bit confused as to how arrays are handled in Objective-C. If I have an array such as

NSarray *myArray = [[NSArray alloc]
                                     


        
3条回答
  •  没有蜡笔的小新
    2021-01-03 08:34

    You can't, because NSArray is immutable. But if you use NSMutableArray instead, then you can. See replaceObjectAtIndex:withObject::

    [myArray replaceObjectAtIndex:0 withObject:@"Y"]
    

提交回复
热议问题