-4

I am trying to do a URL request to an api and return the results.

I am using NSURLConnection in Swift 2

let requestString = "URL HERE"
let urlPath: String = requestString
        let url: NSURL = NSURL(string: urlPath)!
        let request: NSURLRequest = NSURLRequest(URL: url)
        let connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: true)!
        connection.start()

but I keep getting this warning:

'init(request:delegate:startImmediately:)' was deprecated in iOS 9.0: Use NSURLSession (see NSURLSession.h)

I googled the warning and came up with nothing....how do I fix this?

user979331
  • 11,039
  • 73
  • 223
  • 418

1 Answers1

1

Do what the message tells you to do! Use NSURLSession instead. It replaces NSURLConnection, and is far better.

matt
  • 515,959
  • 87
  • 875
  • 1,141