Created
May 26, 2016 15:50
-
-
Save thanhluu/080375c9dcd3fa76646dbaae8d16366e to your computer and use it in GitHub Desktop.
Closures in iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let label = UILabel() | |
func getRecentBlogPost(completion: NSURLResponse -> Void) { | |
let session = NSURLSession(configuration: .defaultSessionConfiguration()) | |
let url = NSURL(string: "http://blog.teamtreehouse.com/api/get_recent_summary?count=20")! | |
let request = NSURLRequest(URL: url) | |
let dataTask = session.dataTaskWithRequest(request) { data, response, error in | |
// Execute body of closure | |
completion(response!) | |
} | |
dataTask.resume() | |
} | |
getRecentBlogPost() { response in | |
print(response) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment