我想知道如何使用结果变量来显示和更新数据。我从 Realm 浏览器监视我的数据在我分配值和写入磁盘时更新。我在控制台中使用 "po object" 打印值,它打印值,但在调试器中,它只显示默认值。 代码示例
let obj = SaloonServices.services[indexPath.section]
cell.serviceLabel.text = obj.name
cell.timeLabel.text = obj.time + " min"
cell.priceLabel.text = "Price: " + obj.price + " SAR"
static var saloons: Results<SaloonCore>!
static func getSaloonFromCore() {
do {
let realm = try Realm()
saloons = realm.objects(SaloonCore.self)
}catch let error {
print("realm Error: " + error.localizedDescription)
}
}
最佳答案
Realm 属性被声明为动态的,并且只能通过生成的 getter 方法读取。 Swift 调试器无法读取动态属性,因此只会显示该数据类型的默认值。
https://realm.io/docs/swift/latest/#debugging
Note that although the LLDB script allows inspecting the contents of your Realm variables in Xcode’s UI, this doesn’t yet work for Swift. Instead, those variables will show incorrect data. You should instead use LLDB’s po command to inspect the contents of data stored in a Realm.
关于swift - Realm 结果值未分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48410399/