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 Downloading JSON Data Asynchronously Returning JSON

I do exactly the same but compiler says

I have written exactly the same but compiler says Use of unresolved identifier with and Use of unresolved identifier completionHandler

Here is the scope:

func FSONTask(with request: URLRequest) -> URLSessionDataTask { let task = session.dataTask(with request: URLRequest, completionHandler completion: @escaping(JSON?, DarkSkyError?)-> Void) -> URLSessionDataTask{ let task = session.dataTask(with: request) { data, response, error in guard let httpResponse = response as? HTTPURLResponse else{ completion(nil, DarkSkyError.responseFailed) return }

Jeff Ripke
Jeff Ripke
41,989 Points

Can you provide us the the rest of the code? Also if you three ` (below the esc key), include the language type after the first three ticks, before and after the code it will be easier for us to read.

func jsonTask(with request: URLRequest, completionHandler completion: @escaping (JSON?, DarkSkyError?) -> Void) -> URLSessionDataTask {
        let task = session.dataTask(with: request) { (data, response, error) in
            // Convert to HTTP Response
            guard let httpResponse = response as? HTTPURLResponse else {
                completion(nil, .requestFailed)
            if httpResponse.statusCode == 200 {
                if let data = data {
                    do {
                        let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: AnyObject]
                        completion(json, nil)
                    } catch {
                        completion(nil, .jsonConversionFailure)
                } else {
                    completion(nil, .invalidData)
            } else {
                completion(nil, .responseUnsuccessful)
        return task