thoughtbot / Argo

Functional JSON parsing library for Swift
https://thoughtbot.com
MIT License
3.49k stars 198 forks source link

Decodable' is ambiguous for type lookup in this context (Swift4) #493

Closed msalmaniftikhar closed 6 years ago

msalmaniftikhar commented 6 years ago

we are updating our app from swift3 to swift4.

Error Messages

Decodable' is ambiguous for type lookup in this context. Cannot convert value of type '([DiaryDecodable.MeetingType]?) -> DiaryDecodable' (aka '(Optional<Array>) -> DiaryDecodable'

Sample JSON

{
    "_links": [],
    "resource": [
        {
            "keyName": "key1",
            "value": "Meeting Location"
        },
        {
            "keyName": "key2",
            "value": "Meeting Details"
        }
}

Models

All models involved, including their Decodable implementations.

struct DiaryDecodable: Diary {
  typealias MeetingType = MeetingDecodable
  var meetings: [MeetingType]? = nil
}

extension DiaryDecodable: Decodable {

  static func decode(_ j: JSON) -> Decoded<DiaryDecodable> {
    let diary = curry(DiaryDecodable.init(meetings:))
    return diary
      <^> j <||? "resource"
  }

}

import Foundation
import Argo
import Runes
import ReactiveSwift
import Curry

Argo Version

Argo 4.1.2

Dependency Manager

Carthage

msalmaniftikhar commented 6 years ago

Resolved it using below code

struct DiaryDecodable: Diary {
  typealias MeetingType = MeetingDecodable
  var meetings: [MeetingType]? = nil
}

extension DiaryDecodable: Argo.Decodable {

  static func decode(_ j: JSON) -> Decoded<DiaryDecodable> {
    return curry(DiaryDecodable.init(meetings:))
      <^> j <||? "resource"
  }

}