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

Stumped on Callback Methods With Closures Challenge 1

I typed this code into Playground and am not receiving any errors. Perhaps I am not understanding the question. Any help much appreciated, Thanks!

Callbacks.swift
import Foundation

typealias BlogPostCompletion = (NSData!,NSURLResponse!, NSError!) -> Void

func fetchTreehouseBlogPosts(completion: BlogPostCompletion) {

}

1 Answer

I just ran into this problem and found the answer here

Basically, just wrap (NSData!, NSURLResponse!, NSError!) -> Void in another set of parentheses. Not sure why though, since Pasan doesn't do it in the video and it works perfectly... Oh well, maybe I'm missing something.

typealias BlogPostCompletion = ((NSData!, NSURLResponse!, NSError!) -> Void)

func fetchTreehouseBlogPosts (completion: BlogPostCompletion) {

}

Oddly I decided to try this as a shot in the dark and it worked for me as well. I then tried to take the question down but couldn't. Thanks for the response though, hopefully it saves somebody some time.