Swift: Determining if cast to integer from string succeeds
<p>Below is my code</p>

<pre><code>func contactForUpdates() -&gt; Int {
    //contact server for most recent version
    let versionURL = settings.versionURL

    if let url = URL(string: versionURL) {
        do {
            let contents = try NSString(contentsOf: url, usedEncoding: nil)
//NEXT LINE IS WHERE THE QUESTIONS LIES
            return Int(contents as String)!
        } catch {
            // contents could not be loaded
            processError("Current version could not be loaded.")
            return Int(0)
        }
    } else {
        // the URL was bad!
        processError("Current version could not be loaded--URL was bad.")
        return Int(0)
    }
}
</code></pre>

<p>If the URL loads, it will return a single integer. A bad internet connection, such as an airport that requires a login prior to internet access, will not return an integer, but a full HTML page that requests a login. forcing a downcast with <code>return Int(contents as String)!</code> will produce the error <code>fatal error: unexpectedly found nil while unwrapping an Optional value</code>.</p>

<p>I assumed that this would run the catch statement when I wrote this, but instead it returns a fatal error. How can I catch this?</p>