Any property RLMObjectsshould be dynamic. Thus, the property amount: NSDecimalNumbershould be defined asdynamic
As below:
private dynamic var _amount: String = ""
public dynamic var amount: NSDecimalNumber {
get { return NSDecimalNumber(string: _amount) }
set { _amount = newValue.stringValue }
}
And the computed property should not be saved. (Of course, the property amount NSDecimalNumber, so it cannot be saved in Realm. If the property amountis saved, an exception has occurred)
, ignoredProperties() "amount" .
override public class func ignoredProperties() -> [AnyObject]! {
return ["amount"]
}
, :
public class Product: RLMObject {
private dynamic var _amount: String = ""
public dynamic var amount: NSDecimalNumber {
get { return NSDecimalNumber(string: _amount) }
set { _amount = newValue.stringValue }
}
public override class func ignoredProperties() -> [String]! {
return ["amount"]
}
}