I'm watching udemy swift tutorial and I saw these two ways of getting data from web:
- Used for getting source code:
var url = NSURL(string: "SOME_URL"); var task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in // some code } )
- Used for downloading an image:
let url = NSURL(string: "SOME_URL") let urlRequest = NSURLRequest(URL: url!) NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (respone, data, error) -> Void in // some code }
My questions:
- Which are differences between them?
- Can I could download an image using first method and viceversa?