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

后端 未结 9 1042
太阳男子
太阳男子 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 21:47

    I had similar error saying : unrecognized selector sent to instance for NSMutable array.. After going through a lot of things, I figured out that I was using my mutable array as a property as

    @property (assign, nonatomic) NSMutableArray *myMutableArray;

    while copy pasting and not paying attention and it was causing the problem.

    The solution us that I changed it to strong type(you can change it to any other type like strong/weak,etc.. depending your requirement). So solution in my case was :

    @property (strong, nonatomic) NSMutableArray *myMutableArray;
    

    So, be careful while copy pasting! Do check once.

提交回复
热议问题