Problem copying NSMutableArray

后端 未结 2 436
孤独总比滥情好
孤独总比滥情好 2021-01-27 12:08

I am trying to copy one array to another:

NSMutableArray *itemsCopy = [[NSMutableArray alloc] initWithArray:self.items copyItems:YES];

but I ge

2条回答
  •  梦如初夏
    2021-01-27 13:13

    You have to provide your classes with the copyWithZone selector (according to NSCopying protocol) if you are not copying objects that implement that protocol by default.

    So if you are copying custom objects you have to implement it. The copy method always calls copyWithZone.. and you must always provide the implementation, it can't know what to copy inside objects by itself..

提交回复
热议问题