Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Swift 2 and Xcode 7 and ge this error

upgraded to xcode 7 and swift 2 and get this error on my basic weather app :

Cannot invoke 'dataTaskWithRequest' with an argument list of type '(NSURLRequest, (_, _, _) throws -> _)'

for my NetworkOperation the erro occurs at the :

let dataTask = session.dataTaskWithRequest(request) { (let data, let response, let error) in

here is the NetworkOperations Code

Import Foundation


class NetworkOperation {

    lazy var config: NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
    lazy var session: NSURLSession = NSURLSession(configuration: self.config)
    let queryURL: NSURL

    typealias JSONDictionaryCompletion = ([String: AnyObject]?) -> Void

    init(url: NSURL) {
        self.queryURL = url
    }


    func downloadJSONFromURL(completion: JSONDictionaryCompletion ) {

        let request: NSURLRequest = NSURLRequest(URL: queryURL)
        let dataTask = session.dataTaskWithRequest(request) { (let data, let response, let error) in

            // 1. Check HTTP response for successfull GET Request

            if let httpResponse = response as? NSHTTPURLResponse {

                switch (httpResponse.statusCode) {
                case 200:
                     // 2. Create JSON object with the data
                    let jsonDictionary = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? [String: AnyObject]
                    completion(jsonDictionary)
                default:
                    print("GET Request not successful. HTTP status Code: \(httpResponse)")
                }

            } else {
                print("Error: Not a Valid HTTP Response")
            }



        }

        dataTask!.resume()

    }


}

1 Answer

I don't think this is it, but were is the closing curly brace in this line of code?

let dataTask = session.dataTaskWithRequest(request) { (let data, let response, let error) in