Skip to content

Instantly share code, notes, and snippets.

@cmoulton
Created September 27, 2015 14:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmoulton/8ce63bd02e3357154385 to your computer and use it in GitHub Desktop.
Save cmoulton/8ce63bd02e3357154385 to your computer and use it in GitHub Desktop.
Add & Remove Session Headers in Alamofire in Swift 2.0
func addSessionHeader(key: String, value: String) {
var headers:[NSObject : AnyObject]
if let existingHeaders =
alamofireManager.session.configuration.HTTPAdditionalHeaders as? [String: String] {
headers = existingHeaders
} else {
headers = Manager.defaultHTTPHeaders
}
headers[key] = value
let config = alamofireManager.session.configuration
config.HTTPAdditionalHeaders = headers
print(config.HTTPAdditionalHeaders)
alamofireManager = Alamofire.Manager(configuration: config)
}
func removeSessionHeaderIfExists(key: String) {
let config = alamofireManager.session.configuration
if var headers = config.HTTPAdditionalHeaders {
headers.removeValueForKey(key)
config.HTTPAdditionalHeaders = headers
alamofireManager = Alamofire.Manager(configuration: config)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment