我正在一个新的iOS Swift项目中使用Realm.我使用的是Xcode 6.0.1,iOS SDK 8.0和Realm 0.85.0
我正在try 使用新的领域主键功能,这样我就可以做addOrUpdateObject
.
以下是一个示例模型:
import Foundation
import Realm
class Foo: RLMObject {
dynamic var id = 0
dynamic var title = ""
func primaryKey() -> Int {
return id
}
}
以及我如何try 添加/更新新对象:
let foo = Foo()
foo.title = titleField.text
foo.id = 1
// Get the default Realm
let realm = RLMRealm.defaultRealm()
// Add to the Realm inside a transaction
realm.beginWriteTransaction()
realm.addOrUpdateObject(foo)
realm.commitWriteTransaction()
我得到了这个错误:
RLMExecption',原因:''Foo'没有主键,因此无法
这是主键上的文档.我可能没有正确设置:
最新的文档现在在这里: