IOS 中的领域:插入对象后无法更改主键 [英] Realm in IOS: Primary key can't be changed after an object is inserted
问题描述
我是使用 Realm 的新手.我有一些代码:
I'm some new in using Realm. I've some code:
RLMRealm *realm = [RLMRealm defaultRealm];
[realm transactionWithBlock:^{
self.object.objectPrimaryKey = someValue;
}];
此字符串出现异常: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?
推荐答案
docs 关于主键,主键只能设置一次.
docs about primary key, you can set primary key only once.
密钥一旦设置就不能更改:覆盖 Object.primaryKey() 以设置模型的主键.声明主键允许有效地查找和更新对象,并强制每个值的唯一性.一旦有主键的对象被添加到 Realm 中,主键就不能更改.
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.
这篇关于IOS 中的领域:插入对象后无法更改主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!