简体   繁体   中英

Realm , Object is already managed by another Realm

  1. Use realm to save data.
  2. Config the realm use defaultconfig.
  3. then , I addOrUpdate some RLMModels
  4. It's success.
  5. I changed the config use

     RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration]; config.fileURL = [[[config.fileURL URLByDeletingLastPathComponent] URLByAppendingPathComponent:@"myname"] URLByAppendingPathExtension:@"realm"]; [RLMRealmConfiguration setDefaultConfiguration:config]; 
  6. I addOrUpdate the same RLMModels

  7. console print error:

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

As the error message states, an object that is already managed by a Realm cannot be added to a different Realm. What you can do instead is create a copy of it in a different Realm using +createInRealm:withValue: .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM