gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 12:53:54 27 4
gpt4 key购买 nike

我刚开始在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com