Cannot convert value of type 'Int64?' to expected argument type 'Int'

AVEbrahimi picture AVEbrahimi · Nov 27, 2017 · Viewed 8.6k times · Source

When I try to pass job?.id (an Int64) as Int parameter ( while I know it's not that big ), swift compiler prompts with this error, I tried a couple of ways to cast it, but had no success :

Cannot convert value of type 'Int64?' to expected argument type 'Int'

My code :

Job.updateJobStatus(token: tok, jobId: job?.id, status:JobSatus.canceled) { (result, error) in
        if result != nil
        {

        }
        else if error != nil
        {

        }
    }

Answer

alitosuner picture alitosuner · Aug 14, 2018

You can easily go like:

let int64Value: Int64 = 123456
let intValue = NSNumber(value: int64Value).intValue