使用 createOrUpdate 的领域部分更新不起作用

Realm partial update using createOrUpdate doesn't work

我正在尝试为我的 iOS 应用程序使用 Realm。当使用 createOrUpate 更新本地 Realm DB 时,它会使用默认值重写未提供的属性,而不是保持它们不变。我使用的领域是最新的,0.93。有人有同样的问题吗?

let realm = RLMRealm.defaultRealm()
realm.beginWriteTransaction()
for matchedUser in matchedUsers {
                    let newMatchedUser = MatchedUser()
                    newMatchedUser.objectId = matchedUser.objectId
                    newMatchedUser.username = matchedUser.username
                    newMatchedUser.email = matchedUser.email
                    newMatchedUser.fullname = matchedUser["fullname"] as! String
                    //they are other properties unprovided here.
MatchedUser.createOrUpdateInDefaultRealmWithValue(newMatchedUser)
                }
                realm.commitWriteTransaction()

所以,我想出了问题所在。事实证明,您不能使用 newMachtedUser 来更新数据库,因为它将首先对其进行初始化,并且将为该初始化过程提供默认值。正确的方法是使用单独的值来更新,或者为该更新创建一个 dictionary/array。