SwiftyJSON & Swift 3: Cannot convert return expression of type 'Int32?' to return type> 'Int?'

We are upgrading to SwiftyJSON Swift 3 with the CocoaPods pod 'SwiftyJSON', '3.1.0' configuration pod 'SwiftyJSON', '3.1.0' .

We get this error:

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

Error in return statement in 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() } } } 

Does anyone know what the problem is? Is this a problem with our CocoaPods configuration or with SwiftyJSON?

+7
swift3 cocoapods swifty-json
source share
4 answers

Implemented a supported version of SwiftyJSON 3.0.0, not 3.1.0. Used 3.0.0, and the problem disappeared.

pod 'SwiftyJSON', '3.0.0'

+4
source share

I will simply replace one line of code with the code below. Plain

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

try it,

Bad: return self.number? .Int32Value

Good: return self.number? .IntValue

Reason: It seems to be more general in how it can return integers.

0
source share

I manually added as? Int as? Int to work again:

 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() } } } 
0
source share

All Articles