Download a webpage


I want to download the source (HTML) of a specific web page, given its complete URL.


// Set the page URL we want to download
let URL = NSURL(string: "")

// Try downloading it
do {
    let htmlSource = try String(contentsOfURL: URL!, encoding: NSUTF8StringEncoding)
catch let error as NSError {
    print("Ooops! Something went wrong: \(error)")

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)