Realm,Object已由另一个Realm管理

时间:2017-11-09 03:00:28

标签: ios realm

  1. 使用领域保存数据。
  2. 配置领域使用defaultconfig。
  3. 然后,我添加或更新一些RLMModels
  4. 这是成功的。
  5. 我更改了配置使用

    RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
    config.fileURL = [[[config.fileURL URLByDeletingLastPathComponent] URLByAppendingPathComponent:@"myname"] URLByAppendingPathExtension:@"realm"];
    [RLMRealmConfiguration setDefaultConfiguration:config];
    
  6. addOrUpdate使用相同的RLMModels

  7. 控制台打印错误:

    2017-11-09 10:50:18.293801+0800 LNLibBase_Example[96588:8779968]
    *** Terminating app due to uncaught exception 'RLMException',
    reason: 'Object is already managed by another Realm. 
    Use create instead to copy it into this Realm.'
    

1 个答案:

答案 0 :(得分:1)

如错误消息所述,已经由Realm管理的对象无法添加到其他Realm。您可以做的是使用+createInRealm:withValue:在不同的Realm中创建副本

相关问题