Problem copying NSMutableArray

后端 未结 2 414
孤独总比滥情好
孤独总比滥情好 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 12:57

    You need to make sure all the contents of self.items adopt the NSCopying protocol.

    If you just want a shallow copy, send the -mutableCopy message to self.items.

    NSMutableArray *itemsCopy = [self.items mutableCopy];
    

提交回复
热议问题