Model not conforming to protocol Decodable
sa7bi opened this issue · 2 comments
sa7bi commented
Hi,
I'm trying to use Argo in my new project, but can't figure out how to solve this problem:
Type 'Comment' does not conform to protocol 'Decodable'
Models
import Argo
import Curry
import Runes
struct Comment {
let id : Int
let user : User
let item : Item
let title : String
let body : String
let createdAt: String
}
extension Comment : Decodable {
static func decode(j: JSON) -> Decoded<Comment> {
return curry(Comment.init)
<^> j <| "id"
<*> j <| "user"
<*> j <| "item"
<*> j <| "title"
<*> j <| "body"
<*> j <| "createdAt"
}
}
struct Item {
let id : Int
let title : String
let price : Double
let description : String?
let createdAt : NSDate
let images : [Media]
let shop : Shop
let user : User
let likes : Int
let comments : [Comment]?
let category : Category
let start : NSDate
let end : NSDate
}
extension Item : Decodable {
static func decode(json: JSON) -> Decoded<Item> {
return curry(Item.init)
<^> json <| "id"
<*> json <| "title"
<*> json <| "price"
<*> json <|? "description"
<*> json <| "createdAt"
<*> json <|| "images"
<*> json <| "shop"
<*> json <| "user"
<*> json <| "likes"
<*> json <|| "comments"
<*> json <| "start"
<*> json <| "end"
}
}
struct User {
let id : Int
let firstName : String
let lastName : String
let avatar : String
let createdAt : String
}
extension User : Decodable {
public static func decode(_ json: JSON) -> Decoded<User>{
return curry(User.init)
<^> json <| "id"
<*> json <| "firstName"
<*> json <| "lastName"
<*> json <| "avatar"
<*> json <| "createdAt"
}
}
Argo Version
Argo 4.1.1
Dependency Manager
Cocoapods
Other
- Xcode : Version 8.2.1
- Swift : 3
Any idea on what am I doing wrong here ??
Thanks
mdiep commented
I think this is because static func decode(j: JSON)
should be static func decode(_ j: JSON)
.