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

4

7

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?

Mend answered 1/10, 2016 at 15:27 Comment(0)
M
4

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'

Mend answered 1/10, 2016 at 15:42 Comment(1)
Did you run the pod update command and let it complete? And do a full clean and build?Mend
C
8

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()
            }
        }
    }
Conflagrant answered 4/10, 2016 at 13:23 Comment(2)
It's valid but our objective is not to modify the client library source.Mend
Yes. i agree with you. we should not modify it. But if we want temp solution to remove erro, we can use above code. In future, we will remove it definatly.Conflagrant
M
4

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'

Mend answered 1/10, 2016 at 15:42 Comment(1)
Did you run the pod update command and let it complete? And do a full clean and build?Mend
W
0

simply try this,

Bad : return self.number?.int32Value

Good : return self.number?.intValue

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

Waxy answered 10/1, 2017 at 11:47 Comment(0)
S
0

I manually added as? Int to get this working 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()
        }
    }
}
Sansom answered 8/2, 2017 at 14:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.