James James - 2 years ago 105
iOS Question

Integer overflows when stored into 'Int Phone Number

In xcode 8, I am getting an error when I try to archive. This is the code:

@IBAction func dialNumber(_ sender: AnyObject) {

if let url = URL(string: "tel://\(8708382937)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)

On the line that begins with "if let..." I am getting this error:
Integer literal '8708382937' overflows when stored into 'Int'

Answer Source

This is expected and a correct error. Why are you putting the number in \()? That evaluates it as Swift. As Swift that's a literal number, which is too big to fit in an Int. You almost certainly mean this:


Or more sensibly:


(The slashes are specifically part of the HTTP URL-scheme. They are not a general part of URLs and do not belong on tel URLs.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download