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 trialWilliam Choi
6,121 PointsStruggling with challenge
Cant seem to figure out how to solve the challenge.
import Foundation
// Add your code below
let fetchTreehouseBlogPosts = session.dataTaskWithRequest(request, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in
})
1 Answer
Jo Albright
5,199 PointsCorrect direction for block. But they are requesting you create a function named "fetchTreehouseBlogPosts" that has a block parameter.
// using typealias
typealias BlogPostCompletion = ((NSData!, NSURLResponse!, NSError!) -> Void)
func fetchTreehouseBlogPosts(completion: BlogPostCompletion) {
}
// not using typealias
func fetchTreehouseBlogPosts(completion: ((NSData!, NSURLResponse!, NSError!) -> Void)) {
}
William Choi
6,121 PointsWilliam Choi
6,121 PointsThanks I was just wondering also if you could help me with the second part of this challenge as well. with concerns to the dataTask, the data thats being returned is it the NSData, NSURLResponse, and the NSError?
and would I write it as a func or a let?
If you could help me with that that would be great. Cheers anyway
Jo Albright
5,199 PointsJo Albright
5,199 PointsIt will be a let.
let dataTask = CREATE_DATATASK_METHOD_WITH_COMPLETION_BLOCK
Just replace that with the correct method that creates a dataTask with a completion block.