TLDR: Use for...of
instead of forEach()
in asynchronous code.
For legacy browsers, use for...i
or [].reduce()
To execute the promises in parallel, use Promise.all([].map(...))
import Foundation | |
let config = NSURLSessionConfiguration.defaultSessionConfiguration() | |
let userPasswordString = "[email protected]:password" | |
let userPasswordData = userPasswordString.dataUsingEncoding(NSUTF8StringEncoding) | |
let base64EncodedCredential = userPasswordData!.base64EncodedStringWithOptions(nil) | |
let authString = "Basic \(base64EncodedCredential)" | |
config.HTTPAdditionalHeaders = ["Authorization" : authString] | |
let session = NSURLSession(configuration: config) |