在目标 c 中填充自定义模型数组崩溃



我的类中有一个变量,它是自定义模型的数组。我想在方法 1 中填充此变量。但是应用程序在此行崩溃:[inboxMessagesArray addObject:entity]

主题 1:EXC_BAD_ACCESS

在 .m 文件中:

@synthesize inboxMessagesArray;

在 .h 文件中:

@property (nonatomic,retain) NSMutableArray<InboxMessagesResponseEntity *> *inboxMessagesArray;

梅霍德1

for (NSDictionary *responseEntityDictionary in dictionary)
{ 
InboxMessagesResponseEntity *entity = [[InboxMessagesResponseEntity alloc] initWithDictionary:responseEntityDictionary error:&err]; 
[inboxMessagesArray addObject:entity];
}

您需要在向数组添加对象之前初始化数组inboxMessagesArray

self.inboxMessagesArray = [NSMutableArray new];  // OR [[NSMutableArray alloc] init];

最新更新