Skip to content

Instantly share code, notes, and snippets.

@jklausa
Created August 27, 2014 21:56
Show Gist options
  • Save jklausa/6a6d3b18af6fbcfc0708 to your computer and use it in GitHub Desktop.
Save jklausa/6a6d3b18af6fbcfc0708 to your computer and use it in GitHub Desktop.
let users = ["klausa_qwpx", "macoscope"]
func getTweetsForUser(userName: String, completion: AnyObject? -> Void) {
let parameters: [String:AnyObject] = ["screen_name": userName, "include_rts": true,
"count": 5, "include_entities": true]
Alamofire.request(.GET, "https//api.twitter.com/1/statuses/user_timeline.json", parameters: parameters)
.responseJSON { (_, _, json, _) in
if let json = json {
completion(json)
}
}
}
var closure: (AnyObject?) -> () = {
if let tweets = $0 as? [[String:String]] {
tweets.map { (tweet: [String:String]) -> () in
let text = tweet["text"]
println("tweet: \(text)")
}
}
}
for user in users {
getTweetsForUser(user, closure)
}
// works
users.map { getTweetsForUser($0, closure) }
// won't compile: Cannot reference a local function from another local function
// bug or Working As Intended?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment