iphone – Objective c将字符串对象添加到数组中

我到处寻找这个,在线,堆栈溢出,并不能解决我做错了什么.

我正在尝试向现有的NSMutableArray添加元素.但它在第4行崩溃:

-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x897b320

代码:

NSMutableArray *mystr = [[NSMutableArray alloc] init];

mystr = [NSArray arrayWithObjects:@"hello",@"world",@"etc",nil];

NSString *obj = @"hiagain";

[mystr addObject:obj];

我究竟做错了什么?这真让我抓狂!!!

解决方法

你的数组不可变!使用NSMutableArray

mystr = [NSMutableArray arrayWithObjects:@"hello",nil];

由于NSArray不包含addObject方法,因此无法识别选择器

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...