ios - 为什么类中的变量返回 nil 而转储类返回所有内容?

标签 ios swift realm

我刚开始在 iOS 中进行开发,我的类 Package 有一个奇怪的问题:

An error

你看,print(data) 返回我的类(包含所有数据),但是当我尝试使用单个变量时,它返回 nil。为什么以及如何修复它?

import RealmSwift

class Package:Object {
    var name:String?
    var code:String?
    var api:String?
    var created_at:NSDate?
    var updated_at:NSDate?
    var progress:[PackageStep] = [PackageStep()]

}

我正在使用 Realm.io 来存储数据库,Packages 从该库的 Object 扩展

最佳答案

Your properties must be declared as dynamic :

Realm model properties need the dynamic var attribute in order for these properties to become accessors for the underlying database data.

There are two exceptions to this: List and RealmOptional properties cannot be declared as dynamic because generic properties cannot be represented in the Objective-C runtime, which is used for dynamic dispatch of dynamic properties, and should always be declared with let.

关于ios - 为什么类中的变量返回 nil 而转储类返回所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35611545/

相关文章:

objective-c - UIDatePicker Date 属性不会设置所选日期 - 而是给出当前日期

iPhone 配置实用程序 - 禁用相机应用程序还会禁用 ImagePicker

ios - 如何用 Storyboard表示查看/编辑模式?

ios - 应该使用什么方法在选择时动态更改 UICollectionViewCell 的大小?

java - 减少应用程序传送的 Realm 数据库的大小

ios - 检查是否在特定日期添加了 Realm 数据

iphone - 在iPhone/iPad上创建新键盘

ios - 如何在两点之间画一条线

swift - 获取错误 : String is not convertible to 'T'

ios - Realm swift : Realm at path already opened with different schema version