Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 领域,对象已由另一个领域管理 使用领域来保存数据 使用defaultconfig配置域 然后,我添加或更新一些rlmmodel 这是成功_Ios_Realm - Fatal编程技术网

Ios 领域,对象已由另一个领域管理 使用领域来保存数据 使用defaultconfig配置域 然后,我添加或更新一些rlmmodel 这是成功

Ios 领域,对象已由另一个领域管理 使用领域来保存数据 使用defaultconfig配置域 然后,我添加或更新一些rlmmodel 这是成功,ios,realm,Ios,Realm,我更改了配置使用 RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration]; config.fileURL = [[[config.fileURL URLByDeletingLastPathComponent] URLByAppendingPathComponent:@"myname"] URLByAppendingPathExtension:@"realm"]; [RLMRealmConfigura

我更改了配置使用

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

  • 控制台打印错误:

    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.'
    

  • 如错误消息所述,无法将已由领域管理的对象添加到其他领域。您可以改为使用在不同领域中创建它的副本。

    错误消息的哪一部分您遇到了问题?给定对象一次只能属于一个领域。如果要将其复制到其他领域,则需要使用
    +createOrUpdateInRealm:withValue:
    。我打包了一个类来管理该操作。.h文件提供addOrUpdate:method和chnageDatabase:method,当有人使用该类时,可以添加或更新:然后,他调用changeDatabase:,下一个调用addOrUpdate:,最后一个错误,我该怎么办,他使用的方法是安全的?我想更改数据库,我需要像这样设置配置:
    RLMRealmConfiguration*config=[RLMRealmConfiguration defaultConfiguration];config.fileURL=[[config.fileURL URLByDeletingLastPathComponent]URLByAppendingPathComponent:@“myname”]URLByAppendingPathExtension:@“realm”];[RLMRealmConfiguration setDefaultConfiguration:config];
    。那么我不能使用旧的RLMModel?我需要创建新的RLMModel?如果在配置中更改文件URL,则打开的是另一个数据库,而不是同一个数据库。因此,是的,您不能将原始数据库中的模型放入新数据库,您需要新的模型对象。