2016-10-01 38 views
7

我們正在使用CocoaPods config pod 'SwiftyJSON', '3.1.0'升級到SwiftyJSON Swift 3。SwiftyJSON&Swift 3:無法轉換類型'Int32?'的返回表達式返回類型>'Int?'

我們收到此錯誤:

/Users/xxx/Documents/iOS/xxx/Pods/SwiftyJSON/Source/SwiftyJSON.swift:866:33: Cannot convert return expression of type 'Int32?' to return type 'Int?'

錯誤是在return語句中SwiftyJSON.swift:

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

任何人都知道是什麼問題?這是我們的CocoaPods配置還是SwiftyJSON的問題?

回答

4

認識到SwiftyJSON的supported version是3.0.0而不是3.1.0。使用3.0.0,問題就消失了。

pod 'SwiftyJSON', '3.0.0'

+1

我試過,但沒有奏效。 – Mehul

+1

您是否運行了pod update命令並讓它完成?並做一個完整的清潔和構建? –

8

我只需更換一行代碼與下面的代碼。簡單

public var int: Int? { 
     get { 
      return self.number?.intValue 
     } 
     set { 
      if let newValue = newValue { 
       self.object = NSNumber(value: newValue) 
      } else { 
       self.object = NSNull() 
      } 
     } 
    } 
+0

這是有效的,但我們的目標不是修改客戶端庫源。 –

+0

是的。我贊同你。我們不應該修改它。但是如果我們想要臨時解決方案來刪除錯誤,我們可以使用上面的代碼。今後,我們會將其清除。 – Mehul

0

只是試試這個,

Bad : return self.number?.int32Value

Good : return self.number?.intValue

Reason : Seems to be more generic in how it can return integers.

0

我手動添加as? Int得到這個工作了:

public var int: Int? { 
    get { 
     return self.number?.int32Value as? Int 
    } 
    set { 
     if let newValue = newValue { 
      self.object = NSNumber(value: newValue) 
     } else { 
      self.object = NSNull() 
     } 
    } 
} 
相關問題