美文网首页
realm 'Can only delete an object

realm 'Can only delete an object

作者: 擅长看漫画的勋同学 | 来源:发表于2018-05-22 16:25 被阅读0次

    realm报错出现这个问题,如果不是Realm对象使用不一致的话,一般是realm对象跨线程使用了,这时候只需要使用-[RLMRealm resolveThreadSafeReference:]就可以了(realm官方文档例子):

    Person *person = [Person new];
    person.name = @"Jane";
    [realm transactionWithBlock:^{
        [realm addObject:person];
    }];
    RLMThreadSafeReference *personRef = [RLMThreadSafeReference
        referenceWithThreadConfined:person];
    dispatch_async(queue, ^{
        @autoreleasepool {
            RLMRealm *realm = [RLMRealm realmWithConfiguration:realm.configuration
                                                         error:nil];
            Person *person = [realm resolveThreadSafeReference:personRef];
            if (!person) {
                return; // person was deleted
            }
            [realm transactionWithBlock:^{
                person.name = @"Jane Doe";
            }];
        }
    });
    

    相关文章

      网友评论

          本文标题:realm 'Can only delete an object

          本文链接:https://www.haomeiwen.com/subject/jzfkjftx.html