NSMutableArray addObject: -[__NSArrayI addObject:]: unrecognized selector sent to instance

后端 未结 9 1057
太阳男子
太阳男子 2020-11-30 21:28

I have tried to initialize my NSMutableArray 100 ways from Sunday, and NOTHING is working for me. I tried setting it equal to a newly allocated and initialized NSMutableArra

9条回答
  •  暖寄归人
    2020-11-30 22:01

    I got bitten by this exception for a typo I've made, maybe it'll save someone 5 min. of their time:

    I wrote:

    NSMutableArray *names = [NSArray array];
    

    instead of:

    NSMutableArray *names = [NSMutableArray array];
    

    The compiler has no problem with that because NSMutableArray is also an NSArray, but it crashes when trying to add an object.

提交回复
热议问题