0

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

错误在行

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

老实说,我不明白出了什么问题,这个项目在 swift 2 中,这发生在迁移到 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 并尝试编译它。

4

0 回答 0