Breakpoint in downloading data from the Web in iOS App development with Swift 3

28 Views Asked by At

I am getting an error while developing an app which downloads data from the Web.

if let url = URL(string: "https://www.stackoverflow.com") {

        let request = NSMutableURLRequest(url: url)

        let task = URLSession.shared.dataTask(with: request as URLRequest) {
            data, response, error in

            if error != nil {
                print(error)
            } else {

                if let unwrappedData = data {

                    let dataString = NSString(data: unwrappedData, encoding: String.Encoding.utf8.rawValue)

                    print(dataString)

                    DispatchQueue.main.sync(execute: {
                    // Update UI

                    })
                }
            }

        }

        task.resume()

    }

I am getting this error (Shown in the image below):

In this image, you can see the error clearly.

Please let me know what's wrong with the code. I am using Swift 3 in Xcode 8 Beta 4.

0

There are 0 best solutions below