Error when specifying type in swift 3
HugoSay opened this issue · 8 comments
Hi there
I'm converting my project to swift 3 and i'm sadly having problems with a large model (14 properties) I tried to add the types to my decode function as mentioned here but it sends me the following error
Error Messages
No '<|' candidates produce the expected contextual result type 'Decoded<_>'
Models
All models involved, including their Decodable
implementations.
(here is a test with a smaller model)
/**
* Represent the response comming from the api
*/
public struct Yield {
public let quantity: Int //Identifier of step
public let unit: String //Description of step
public let display: String //Type of step PREPRATION
}
extension Yield: Decodable {
public static func decode(_ json: JSON) -> Decoded<Yield> {
let decoded = curry(Yield.init)
return decoded
<^> json <| "quantity" as Decoded<Int>
<*> json <| "unit" as Decoded<String>
<*> json <| "quantityDisplay" as Decoded<String>
}
}
Argo
- Argo (4.0.0):
Dependency Manager
Cocoapods,
Is this an abbreviated version of your model? You say you have 14 properties but your sample only has 3. The sample you provided appears to be correct (although for 3 properties you shouldn't need to use any of these workarounds) but I'd like to see the full model if there's more context.
Oh sorry about that. This version is just a test (with fewer properties for speed purpose).
The issue is that this piece of code doesn't compile either (with the error message i gave above)
I am getting more or less the same errors. Seems like <| operator cannot be recognized. I am using Argo 4.1.0 through Cocoapods. In addition to the similar error above. I am also getting errors 'Operator is not a known binary operator' where I use <|
struct ValidatePatientName
{
public let found:Int
public let firstName:String
public let lastName:String
}
extension ValidatePatientName:Decodable {
public static func decode(_ json:JSON) -> Decoded<ValidatePatientName>{
return curry(ValidatePatientName.init)
<^> json <| "found"
<*> json <| "first_name"
<*> json <| "last_name"
}
}
@abdullahnkhan Are you importing Runes
alongside Argo
for these files? That's something that changed with Argo 4.0.
@gfontenot Many thanks. This fixed it. Sorry, if I missed something obvious :-|
@HugoSay It looks like wrapping json <| "foo"
in parens fixes the compilation errors. Looks like this is an unfortunate side-effect of the operator precedence changes we had to make as a part of our Swift 3 migration.
@abdullahnkhan No worries! Glad I could help get it worked out.
I'm going to go ahead and close this, since it looks like the issue is resolved. Please re-open if that's not the case.