ios - setValue(value, forKey) 以某种方式改变了 Realm 中的整个数组

标签 ios swift realm

我尝试更改我创建的对象中的值。但不知何故,在这个简单的操作之后,整个数组正在编辑。

这是 Swift 4.2,我使用的是 Realm 和 iOS 12.4。

let index = indexes[i].map { String($0) }.joined(separator: "")
//index is "00"

let obj = object[index] 
print(object)

let key = (o.value)["values"].array![Int(key.0)!]
obj?.setValue(res, forKey: key["prop_name"].string!) //example data provided in screenshot

print("Adding property " + (key["prop_name"].string! ) + " with value '" + (key["value"].string!) + "' = " + res) //in example I add property 'number' with value = 1
print(object)

我期望一个对象发生变化。

Swift's prints

最佳答案

可怜的我。

Realm 将您之前创建的Object 与数组链接起来。

所以我需要创建不同的对象并将它们放入这个数组中。我每次都编辑相同的对象

关于ios - setValue(value, forKey) 以某种方式改变了 Realm 中的整个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57246623/

相关文章:

macos - "Cannot create asynchronous query while in a write transaction"异常

ios - 在 iOS 5 上实现快速高效的核心数据导入

javascript - 如何计算javascript中的日出和日落?

ios - 当字符串为空时,componentsSeparatedByString 返回 1 个对象

ios - 处理通知中 View 的点击

arrays - Swift String.Index 与将字符串转换为数组

ios - 在 Swift 中使用 Realm

json - 用于解析 JSON 并返回字典数组的 Swift 函数

string - 我如何获得键值? - 为什么方法不起作用?

ios - 在 Realm 迁移中使用新属性的默认值