【问题标题】:Realm in IOS: Primary key can't be changed after an object is insertedIOS中的领域:插入对象后无法更改主键
【发布时间】:2018-07-24 14:36:18
【问题描述】:

我是使用 Realm 的新手。我有一些代码:

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

此字符串出现异常:self.object.objectPrimaryKey = someValue;,原因:'Primary key can't be changed after an object is inserted.'

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

【问题讨论】:

    标签: ios objective-c realm


    【解决方案1】:

    docs关于主键,主键只能设置一次。

    密钥一旦设置就无法更改: 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.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多