We are upgrading to SwiftyJSON Swift 3 with CocoaPods config pod 'SwiftyJSON', '3.1.0'
.
We are getting this error:
/Users/xxx/Documents/iOS/xxx/Pods/SwiftyJSON/Source/SwiftyJSON.swift:866:33: Cannot convert return expression of type 'Int32?' to return type 'Int?'
Error is on the 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()
}
}
}
Anyone know what the issue is? Is this an issue with our CocoaPods config or with SwiftyJSON?
SwiftyJSON is a library that helps to read and process JSON data from an API/Server. So why use SwiftyJSON? Swift by nature is strict about data types and wants the user to explicitly declare it. This becomes a problem as JSON data is usually implicit about data types.
Alamofire is an HTTP networking library written in Swift. SwiftyJSON makes it easy to deal with JSON data in Swift. Steps to setup the CocoaPods. Open Terminal. CocoaPods runs on ruby so update your system.
Adding SwiftyJSON to the demo project Here's our path: Xcode > ( Xcode project name) > Targets > (Xcode project name). In the General tab, under the Frameworks and Libraries dropdown, we click on + and select Add package dependency. Then, we enter the package Git URL: https://github.com/SwiftyJSON/SwiftyJSON.git.
An object that converts between JSON and the equivalent Foundation objects.
I Just replace one line of code with below code. Simple
public var int: Int? {
get {
return self.number?.intValue
}
set {
if let newValue = newValue {
self.object = NSNumber(value: newValue)
} else {
self.object = NSNull()
}
}
}
Realized the supported version of SwiftyJSON is 3.0.0 and not 3.1.0. Used 3.0.0 and the issue went away.
pod 'SwiftyJSON', '3.0.0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With