Is it possible to extend NSDecimalNumber
to conform Encodable & Decodable
protocols?
相关问题
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
- Get the NSRange for the visible text after scroll
- UIPanGestureRecognizer is not working in iOS 13
- What does a Firebase observer actually do?
相关文章
- Using if let syntax in switch statement
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
- How can I vertically align my status bar item text
- Adding TapGestureRecognizer to UILabel in Swift
- Attempt to present UIAlertController on View Contr
- Swift - Snapshotting a view that has not been rend
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 toDecimal
It is not possible to extend
NSDecimalNumber
to conform toEncodable
&Decodable
protocols. Jordan Rose explains it in the following swift evolution email thread.If you need
NSDecimalValue
type in your API you can build computed property aroundDecimal
.Btw. If you are using
NSNumberFormatter
for parsing, beware of a known bug that causes precision loss in some cases.Parse strings this way instead: