0

app crash when we add Unmanaged Object to array of another another unmanaged object.

@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

My app crash when i try to add call detail from my json response, here is my code

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];

Error I got

Terminating app due to uncaught exception 'RLMException', reason: 'Invalid value (NSPoint: {0, 0}) for 'JOAttachment' array property 'JOCallDetail.attachmentUrls': value is not enumerable.'

Er. Khatri
  • 1,384
  • 11
  • 29
  • Is there an error message in console? Use `copy` instead of `assign`? If it's a NSObject, `assign` seems strange: https://stackoverflow.com/questions/43641072/rlmarray-properties-in-unmanaged-rlmobjects-in-objective-c – Larme Jul 09 '18 at 10:41
  • i have added the error in question, it is about my error is not enumerable although it is – Er. Khatri Jul 09 '18 at 11:01

0 Answers0