Created
September 10, 2015 13:37
-
-
Save nRewik/90934db45262f34e00b4 to your computer and use it in GitHub Desktop.
an example of request chaining using NSURLSession Callback
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
// 1. login post request | |
NSURLSession.sharedSession().dataTaskWithRequest(loginRequest){ data , res , err in | |
// let token = data... | |
// we have token. | |
let getCurrentUserURL = NSURL(string: getUserDataURL + "?token=\(token)")! | |
// 2. get current user data | |
NSURLSession.sharedSession().dataTaskWithURL(getCurrentUserURL){ data , res , err in | |
// we have user data, and we get currentUserID | |
let _getAddressesesURL = NSURL(string: getAddressesURL + "?token=\(token)&userId=\(currentUserID)")! | |
// 3. get last friend user data | |
NSURLSession.sharedSession().dataTaskWithURL(_getAddressesesURL){ data , res , err in | |
// we have addresses. we're done | |
println("done") | |
}.resume() | |
}.resume() | |
}.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment