SwiftyJSON和Swift 3:无法转换'Int32'类型的返回表达式?返回类型>'Int?'

Mar*_*eon 7 cocoapods swifty-json swift3

我们正在使用CocoaPods配置升级到SwiftyJSON Swift 3 pod 'SwiftyJSON', '3.1.0'.

我们收到此错误:

/Users/xxx/Documents/iOS/xxx/Pods/SwiftyJSON/Source/SwiftyJSON.swift:866:33:无法转换'Int32?'类型的返回表达式?返回类型'Int?'

错误发生在SwiftyJSON.swift的return语句中:

public var int: Int? {
    get {
        return self.number?.int32Value
    }
    set {
        if let newValue = newValue {
            self.object = NSNumber(value: newValue)
        } else {
            self.object = NSNull()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

谁知道问题是什么?这是我们的CocoaPods配置还是使用SwiftyJSON的问题?

Meh*_*hul 8

我只需用下面的代码替换一行代码.简单

public var int: Int? {
        get {
            return self.number?.intValue
        }
        set {
            if let newValue = newValue {
                self.object = NSNumber(value: newValue)
            } else {
                self.object = NSNull()
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)


Mar*_*eon 4

意识到SwiftyJSON支持的版本是 3.0.0 而不是 3.1.0。使用3.0.0,问题就消失了。

pod 'SwiftyJSON', '3.0.0'