没有'< ||?'候选人产生预期的上下文结果类型'Decoded< _>'

时间:2017-01-08 10:46:34

标签: swift swift3 decode argo

我有一个项目,我正在使用Argo,我收到标题中提到的错误。

错误在行

<*> json <||? ["info", "images", "poster_original"]

老实说,我无法理解什么是错的,这个项目很快就有了什么,这在迁移到swift 3时就发生了。

我的依赖关系是(如果您认为存在某种冲突):

pod 'Alamofire', '~> 4.2'
pod 'Kingfisher', '~> 3.2'
pod 'Argo', '~> 4.1'
pod 'Curry', '~> 3.0'
pod 'SwiftyUserDefaults', '~> 3.0'

这是我的班级:

class Movie: Decodable {

    public static func decode(_ json: JSON) -> Decoded<Movie> {
        let a = curry(Movie.init)
            <^> json <| "title"
            <*> json <||? ["info", "rating", "imdb"]
            <*> json <||? ["info", "images", "poster"]
            <*> json <|? ["info", "imdb"]
            <*> json <|? ["info", "plot"]

        let b = a
            <*> json <| ["info", "year"]
            <*> json <|? ["info", "runtime"]
            <*> json <|? ["info", "tagline"]
            <*> json <|? ["info", "mpaa"]
            <*> json <|| ["info", "genres"]


        let c = b
            <*> json <||? ["info", "images", "poster_original"]
            <*> json <||? ["info", "images", "backdrop"]
            <*> json <||? ["info", "images", "backdrop_original"]
            <*> .optional(json <| ["info", "images", "actors"] >>- { [String: String].decode($0) })
            <*> json <|? "status"
            <*> json <|? ["info", "in_wanted", "status"] <|> pure(nil)



        if let error = c.error {
            NSLog("### ERROR DECODING DISCOVERY MOVIE --> \(error.description)")
        }

        return c
    }

    let name: String
    let rating: [Float]?
    let postersUrls: [String]?
    let imdbId: String?
    let plot: String?
    let year: Int
    let length: Int?
    let tagline: String?
    let mpaa: String?
    let genres: [String]
    let postersOriginalUrls: [String]?
    let backdropsUrls: [String]?
    let backdropsOriginalUrls: [String]?
    let actorsWithPictures: [String: String]?
    let libraryStatus: String?
    let wantedStatus: String?

    var status: MovieStatus
    var mainPosterUrl: String? {

        if let urls = postersOriginalUrls, urls.count > 0 {
            return urls.first
        }

        if let urls = postersUrls, urls.count > 0 {
            return urls.first
        }

        return nil

    }

    init(name: String,
         rating: [Float]?,
         postersUrls: [String]?,
         imdbId: String?,
         plot: String?,
         year: Int,
         length: Int?,
         tagline: String?,
         mpaa: String?,
         genres: [String],
         postersOriginalUrls: [String]?,
         backdropsUrls: [String]?,
         backdropsOriginalUrls: [String]?,
         actors: [String: String]?,
         libraryStatus: String?,
         wantedStatus: String?) {

        self.name = name
        self.rating = rating
        self.postersUrls = postersUrls
        self.imdbId = imdbId
        self.plot = plot
        self.year = year
        self.length = length
        self.tagline = tagline
        self.mpaa = mpaa
        self.genres = genres
        self.postersOriginalUrls = postersOriginalUrls
        self.backdropsUrls = backdropsUrls
        self.backdropsOriginalUrls = backdropsOriginalUrls
        self.actorsWithPictures = actors
        self.libraryStatus = libraryStatus
        self.wantedStatus = wantedStatus

        self.status = MovieStatus.statusFromLibraryStatus(ls: libraryStatus, andWantedStatus: wantedStatus)
    }

}

更新

我创建了一个MCVE,您可以从https://drive.google.com/open?id=0B35AMbs00yEQWHc2M2s1bDdDdVk下载它,只需打开xcworkspace并尝试编译它。

0 个答案:

没有答案