应用崩溃。
@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'数组属性的值无效(NSPoint:{0,0}) ''JOCallDetail.attachmentUrls':值不可枚举。'