领域非托管RLMArray

时间:2018-07-09 10:38:44

标签: objective-c realm realm-mobile-platform rlmarray realm-database

当我们将非托管对象添加到另一个另一个非托管对象的数组时,

应用崩溃。

@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':值不可枚举。'

0 个答案:

没有答案