我刚开始在 iOS 中进行开发,我的类 Package
有一个奇怪的问题:
你看,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
andRealmOptional
properties cannot be declared asdynamic
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 withlet
.
关于ios - 为什么类中的变量返回 nil 而转储类返回所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35611545/