My approach fails. n
is set to nil
, whereas it is set correctly if its type is Double?
. Is there a correct way to do this?
class Model: Mappable
{
var n: NSDecimalNumber?
required init?(_ map: Map)
{
super.init()
mapping(map)
}
func mapping(map: Map)
{
n <- map["n"]
}
}
ObjectMapper doesn't support NSDecimalNumber. We are avoiding Objective-C types when possible.
If you need a NSDecimalNumber, you can consider using a CustomTransform to support it.
NSDecimalNumber must be taken in consideration. There is no replacement for this type in Swift. This is the only type that can be used to represent money. Double or float is not an alternative.
@jonasman While I agree with you, there is an included NSDecimalNumberTransform in ObjectMapper, so this is a minor inconvenience.
That sounds good then.
Most helpful comment
NSDecimalNumber must be taken in consideration. There is no replacement for this type in Swift. This is the only type that can be used to represent money. Double or float is not an alternative.