我有两个类 - BNRItem和BNRContainer。 BNRContainer是BNRItem的一个子类。为了减少代码我贴的数量,假设以下是我已经测试并知道作品:为什么我在尝试将对象添加到NSMutableArray时遇到SIGABRT
+(BNRItem *) randomItem; // allocate and init a random item.
@property(nonatomic, readwrite, copy) NSMutableArray * subitems; // This is a property of BNRContainer class
main.m:
NSMutableArray * rand_items = [NSMutableArray alloc] init];
for (int i = 0; i < 10; i++) {
[rand_items addObject: [BNRItem randomItem]];
}
[rand_items addObject: @"HELLO"];
BNRContainer * rand_container_of_items = [BNRContainer randomItem];
rand_container_of_items.subitems = rand_items;
[rand_container_of_items.subitems addObject: @"THERE"]; // ERROR SIGABRT
NSLog(@"------------------------------------------------------");
NSLog(@"%@", rand_container_of_items);
rand_container_of_items = nil;
如果我NSLog
无需添加@“有”,我看到“Hello”在我的描述,所以我知道我可以在那个时候致电addObject:
。当我试图访问rand_container_of_items的ivar“子项目”时,为什么我会得到SIGABRT?我无法弄清楚这一点。
PLZ,没有更多的snake_case! – Dam