RealmSwift 嵌套对象 getter 未返回数据
RealmSwift nested object getter not returning data
我的 Realm 对象在尝试访问 属性 时返回 0 时遇到一些问题。
当我这样做时:
print(calculation)
print(calculation.homePrice)
它给了我:
PaymentsCalculation {
id = 90941762-E648-4377-ABA3-4BDA88880768;
homePrice = 200000;
downPayment = 40000;
interestRate = 0.04;
homeInsurance = 900;
HOADues = 0;
loanType = 30-year fixed;
hidePMI = 0;
}
0.0
为什么会这样?
计算是来自 User
class:
的嵌套对象
import RealmSwift
class User: Object {
var id: String = NSUUID().UUIDString
let monthlyPayments = List<PaymentsCalculation>()
override static func primaryKey() -> String? {
return "id"
}
}
多哈
忘记了 dynamic
homePrice
如果有人遇到同样的问题:
记得这样做:
dynamic var homePrice: Double = 0.0
我的 Realm 对象在尝试访问 属性 时返回 0 时遇到一些问题。
当我这样做时:
print(calculation)
print(calculation.homePrice)
它给了我:
PaymentsCalculation {
id = 90941762-E648-4377-ABA3-4BDA88880768;
homePrice = 200000;
downPayment = 40000;
interestRate = 0.04;
homeInsurance = 900;
HOADues = 0;
loanType = 30-year fixed;
hidePMI = 0;
}
0.0
为什么会这样?
计算是来自 User
class:
import RealmSwift
class User: Object {
var id: String = NSUUID().UUIDString
let monthlyPayments = List<PaymentsCalculation>()
override static func primaryKey() -> String? {
return "id"
}
}
多哈
忘记了 dynamic
homePrice
如果有人遇到同样的问题:
记得这样做:
dynamic var homePrice: Double = 0.0