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

Alexey Kuznetsov
Alexey Kuznetsov
9,516 Points

Build a Weather App With Swift -> Managing complexity -> 1st challenge

Got no errors, where is mistake? Or i just didn't understand the task?

Callbacks.swift
import Foundation

// Add your code below
typealias BlogPostCompletion = (NSData!, NSURLResponse!, NSError!) -> Void

    func fetchTreehouseBlogPosts(completion: BlogPostCompletion) {

    }
Corey Dutson
Corey Dutson
Courses Plus Student 3,193 Points

Hey there! I'm getting the exact same problem right now. I've dumped my code into xcode and it all seems syntactically correct. Here's what I've tried:

import Foundation

// Add your code below

// 1.
typealias BlogPostCompletion = (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void
func fetchTreehouseBlogPosts(completion: BlogPostCompletion) {}

// 2. 
typealias BlogPostCompletion = (data: NSData!, response: NSURLResponse!, error: NSError!) -> ()
func fetchTreehouseBlogPosts(completion: BlogPostCompletion) {}

// 3.
typealias BlogPostCompletion = (NSData!, NSURLResponse!, NSError!) -> Void
func fetchTreehouseBlogPosts(completion: BlogPostCompletion) {}

// 4.
typealias BlogPostCompletion = (NSData!, NSURLResponse!, NSError!) -> ()
func fetchTreehouseBlogPosts(completion: BlogPostCompletion) {}

// 5.
func fetchTreehouseBlogPosts(completion: (NSData!, NSURLResponse!, NSError!) -> Void) {}

// 6.
func fetchTreehouseBlogPosts(completion: (NSData!, NSURLResponse!, NSError!) -> ()) {}

// 7.
func fetchTreehouseBlogPosts(completion: (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void) {}

// 8.
func fetchTreehouseBlogPosts(completion: (data: NSData!, response: NSURLResponse!, error: NSError!) -> ()) {}

I should note that I'm aware some are not correct (1,2,7,8) because they shouldn't be named, but I wanted to be thorough.

EDIT: I've figured it out, though it seems to be a bug with the code checker itself. I've added my answer below.

2 Answers

Corey Dutson
PLUS
Corey Dutson
Courses Plus Student 3,193 Points

Turns out for whatever reason, you need to throw an extra set of () around the callback declaration. Pasan doesn't do this in the video, nor does xcode correct you on it... I feel like this may be a Swift 1.0 thing that changed and the code checker was never updated on.

Anyways here's a working answer:

import Foundation

// Add your code below
typealias BlogPostCompletion = ((NSData!, NSURLResponse!, NSError!) -> Void)
func fetchTreehouseBlogPosts(completion: BlogPostCompletion) {}
Alexey Kuznetsov
Alexey Kuznetsov
9,516 Points

Thank you! I tried all the options except the last one, I didn't even occur, that problem was here.