Skip to content

Instantly share code, notes, and snippets.

@Marcocanc
Last active April 20, 2017 09:24
Show Gist options
  • Save Marcocanc/04940fe490afd52dc97e39ef0eeaabed to your computer and use it in GitHub Desktop.
Save Marcocanc/04940fe490afd52dc97e39ef0eeaabed to your computer and use it in GitHub Desktop.
JSON+Decimal
import Foundation
import SwiftyJSON
extension JSON {
public var decimal: Decimal? {
get {
switch self.type {
case .string:
return Decimal(string: self.object as! String)
case .number:
return (self.object as! NSNumber).decimalValue
default:
return nil
}
}
}
public var decimalValue: Decimal {
get {
return self.decimal ?? Decimal()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment