当我们将非托管对象添加到另一个非托管对象的数组时,应用程序崩溃。
@interface JOCallDetail : RLMObject
@property (nonatomic, strong) NSString * primaryId;
@property (nonatomic, assign) RLMArray<JOAttachment> *attachmentUrls;
@end
@implementation JOCallDetail
+(NSString *)primaryKey{
return @"primaryId";
}
+(JOCallDetail *)initWithJSONDictionary:(NSDictionary *)dictionary{
NSString *primaryId = dictionary[@"call_id"];
JOCallDetail *cd=[[JOCallDetail alloc]init];
cd.primaryId=primaryId;
for (NSDictionary *at in dictionary[@"attachment_urls"]) {
NSString *url=at[@"url"];
if (!url.length) {
url=at[@"media_url"];
}
JOAttachment *a = [[JOAttachment alloc]init];
a.attachmentId = at[@"attachment_id"];
a.mediaUrl = url?url:@"";
a.dataFrom = 0;
a.mediaType = @"image";
a.referenceId = primaryId;
[cd.attachmentUrls addObject:a];
}
return cd;
}
@end
当我尝试从我的 json 响应中添加呼叫详细信息时,我的应用程序崩溃了,这是我的代码
RLMRealm *realm = [RLMRealm defaultRealm];
[realm transactionWithBlock:^{
NSMutableArray *allPendingCalls = [jsonDict[@"current_calls"] mutableCopy];
for (NSDictionary *pendingCall in allPendingCalls) {
JOCallDetail *cd = [JOCallDetail initWithJSONDictionary:pendingCall];
[realm addOrUpdateObject:cd];
}
} error:nil];
我得到的错误
由于未捕获的异常“RLMException”而终止应用程序,原因:“JOAttachment”数组属性“JOCallDetail.attachmentUrls”的值无效(NSPoint:{0, 0}):值不可枚举。