问题
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