Making NSDecimalNumber Codable

后端 未结 2 1673
逝去的感伤
逝去的感伤 2021-02-19 23:08

Is it possible to extend NSDecimalNumber to conform Encodable & Decodable protocols?

2条回答
  •  情深已故
    2021-02-19 23:38

    In swift you should use Decimal type. This type confirms to protocols Encodable & Decodable from the box.

    If you have NSDecimalNumber type in your code it's easy to cast it to Decimal

    let objcDecimal = NSDecimalNumber(decimal: 10)
    let swiftDecimal = (objcDecimal as Decimal)
    

提交回复
热议问题