The Beanstalk
The Beanstalk

Reputation: 808

NSURLSession Initializer error

I'm trying to create an NSURLSession like so:

let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(), delegate:self, delegateQueue: NSOperationQueue.mainQueue())

so I can do some downloading and such, but I keep getting this error:

Cannot find initializer for type 'NSURLSession' that accepts an argument list of type '(configuration: NSURLSessionConfiguration, delegate: AppDelegate, delegateQueue: NSOperationQueue)'

I've check the documentation and there definitely is an initializer with those arguments. What's going on here?

Upvotes: 2

Views: 290

Answers (1)

zaph
zaph

Reputation: 112857

You need to add NSURLSessionDelegate as a protocol to the class declaration.

class TheClassName: SuperClassName, NSURLSessionDelegate {

The error messages states:

Cannot find initializer for type 'NSURLSession' that accepts an argument list of type
'(configuration: NSURLSessionConfiguration, delegate: AppDelegate, delegateQueue: NSOperationQueue)'

The documentation for the initializer:
init(configuration configuration: NSURLSessionConfiguration, delegate delegate: NSURLSessionDelegate?, delegateQueue queue: NSOperationQueue?)

Take away: read the error messages really carefully.

Upvotes: 4

Related Questions