Weird Issue: Integer Literal Overflows!?!?

Okay, I am getting this strange error in xcode 8. In the below code, which is for dialing a number,:

@IBAction func dialNumber(_ sender: AnyObject) {
        if let url = URL(string: "tel:/"tel://\(8708382937)") { 
UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
    }

I am getting the error: "Integer literal '8708382937' overflows when stored into 'Int"' On line 02.

This code was working just fine in xcode 7. Any help?

Accepted Reply

It happens when your target is a 32-bit device (such as iPhone 5). There are several workarounds:

1. Use a string, since you are hard-coding the value anyway:

if let url = URL(string: "tel://8708382937") {

2. Cast it to Int64:

if let url = URL(string: "tel://\(8708382937 as Int64)") {

3. Use a variable and specify the type:

let tel: Int64 = 8708382937
if let url = URL(string: "tel://\(tel)") {

Swift is inferring a type of Int for the integer literal, which has a max value of 2147483647 on a 32-bit system.

Replies

It happens when your target is a 32-bit device (such as iPhone 5). There are several workarounds:

1. Use a string, since you are hard-coding the value anyway:

if let url = URL(string: "tel://8708382937") {

2. Cast it to Int64:

if let url = URL(string: "tel://\(8708382937 as Int64)") {

3. Use a variable and specify the type:

let tel: Int64 = 8708382937
if let url = URL(string: "tel://\(tel)") {

Swift is inferring a type of Int for the integer literal, which has a max value of 2147483647 on a 32-bit system.