-
Notifications
You must be signed in to change notification settings - Fork 91
Possible to extend Money to conform to Decodable
?
#35
Comments
Hi @irace, thanks for the suggestion. I'll take a look into it, this week hopefully.
|
So.... just been looking into this. Not really sure how I can make @irace if you're still interested in this, can you provide a bit more information about what you're trying to do, or how you envisage using Money? |
Usage would be a model object like: struct Transaction {
let price: Money
}
extension Transaction: Decodable {
static func decode(object: AnyObject) throws -> Transaction {
return try Transaction(price: object => "price")
}
} This would be possible if one could extend I’m not suggesting that Might be worth just not worrying about until Swift 3.0 is out and it can be worked around as per my original description. |
Arr - I see what you're getting at! There is another issue here about creating values if given the currency code as a string, which is totally not as I've written this framework at all. I've been thinking of how to make that work, (conforming to Potentially, I'll re-write the entirely library different to be able to accommodate this kind of usage, but will probably have to wait until Swift 3.0 |
I’m trying to get
Money
to conform to Decodable, but it doesn’t seem possible.You can’t directly extend
Money
(“Constrained extension must be declared on the unspecialized generic type_Money
with constraints specified by a 'where' clause”).You also can’t constrain an extension and specify that the constrained extension conforms to a protocol, e.g.:
This is unfortunately just a Swift compiler limitation, this has already been promised in Swift 3.0.
Any ideas?
The text was updated successfully, but these errors were encountered: