Created
September 27, 2015 14:28
-
-
Save cmoulton/8ce63bd02e3357154385 to your computer and use it in GitHub Desktop.
Add & Remove Session Headers in Alamofire in Swift 2.0
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 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