Created
September 10, 2015 13:28
-
-
Save nRewik/bc5cd2dd5a6f09c4072a to your computer and use it in GitHub Desktop.
an example of how to create an async promise task
This file contains 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
func getUserData(#token: String) -> Promise<User>{ | |
return Promise<User>{ fulfill, reject in | |
let task = NSURLSession.sharedSession().dataTaskWithURL(self.getCurrentUserURL){ data , res , err in | |
if let err = err{ | |
return reject(err) | |
} | |
let user = User(data: data) | |
return fulfill(user) | |
} | |
task.resume() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment