swift - Realm 结果值未分配

标签 swift realm realm-mobile-platform

我想知道如何使用结果变量来显示和更新数据。我从 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/

相关文章:

swift - Realm Sync Facebook 身份验证不起作用

android - 当用户从商店更新 Android 应用程序时,Realm 数据库会发生什么变化?

ios - Realm 对象服务器创建数据库和 ROS 但不同步

swift - 以编程方式更改 Google map 大小 (Swift)

ios - UIImageView 将(segue)nil 传递给另一个 ViewController

swift - NSURL.URLByAppendingPathComponent() 的 Swift 3 等价物是什么?

android - 是否可以部分更新 RealmObject

ios - Facebook 注销按钮(iOS SDK)在注销时适当的 segue

ios - 在 Realm 中查询(使用 Swift)

java - Realm 异常 : java. lang.UnsupportedOperationException:缺少 Not 参数