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 Build a Weather App with Swift Managing Complexity Callback Methods With Closures

Girri M Palaniyapan
Girri M Palaniyapan
7,829 Points

Please help check code. Unclear why code is wrong.

Hi, I think I am doing the steps right, I keep on getting the same error message asking me to check whether the method's name and syntax is right.

Callbacks.swift
import Foundation

class NetworkOperation {
    lazy var config : NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration()
    lazy var session : NSURLSession = NSURLSession(configuration: self.config)

    let queryURL: NSURL

    init(url: NSURL){
        self.queryURL = url
    }
    typealias BlogPostCompletion = ([String:AnyObject]? -> ())

    func fetchTreehouseBlogPosts (completion: BlogPostCompletion) {
        let request: NSURLRequest = NSURLRequest(URL: queryURL)
        let dataTask = session.dataTaskWithRequest(request) {
            (let data, let response, let error) in
            if let httpResponse = response as? NSHTTPURLResponse {
                switch(httpResponse.statusCode){
                case 200:
                    //Create a JSON object from the data
                    let jsonDictionary = NSJSONSerialization.JSONObjectWithData(data , options: nil , error: nil) as? [String: AnyObject]
                    completion(jsonDictionary)



                default: "GET Request not successful. Error code is \(httpResponse)"
                }


            } else {
                println("Error: Not a valid HTTP response")
            }



        }




        dataTask.resume()

    }}
James Hoffman
James Hoffman
6,354 Points

Only problem I see is that you are missing the println statement here: default: "GET Request not successful. Error code is (httpResponse)" Hope this helps!