Last active
April 20, 2017 09:24
-
-
Save Marcocanc/04940fe490afd52dc97e39ef0eeaabed to your computer and use it in GitHub Desktop.
JSON+Decimal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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