Realm in IOS: Primary key can't be changed after an object is inserted

夙愿已清 提交于 2019-12-24 18:23:03

问题


I'm some new in using Realm. I've some code:

RLMRealm *realm = [RLMRealm defaultRealm];
            [realm transactionWithBlock:^{
                self.object.objectPrimaryKey = someValue;
            }];

An exception occures on this string: self.object.objectPrimaryKey = someValue; with reason: 'Primary key can't be changed after an object is inserted.'

objectPrimaryKey is a primary key. What can I do to fix it?

回答1:


docs about primary key, you can set primary key only once.

You can't change key once it's set: Override Object.primaryKey() to set the model’s primary key. Declaring a primary key allows objects to be looked up and updated efficiently and enforces uniqueness for each value. Once an object with a primary key is added to a Realm, the primary key cannot be changed.



来源:https://stackoverflow.com/questions/51501353/realm-in-ios-primary-key-cant-be-changed-after-an-object-is-inserted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!