I am tired of trying to manually replace the entire application by adding headers to 100+ of my queries. I chose a more lazy approach:
Make AlamofireManagerExtension.swift and use the following code:
import Foundation import Alamofire extension Manager { public func myRequest( method: Alamofire.Method, _ URLString: URLStringConvertible, parameters: [String: AnyObject]? = nil, encoding: ParameterEncoding = .URL, headers: [String: String]? = ["MY-STATIC-API-KEY" : "BLAHBLAHBLAH"]) -> Request { return Manager.sharedInstance.request( method, URLString, parameters: parameters, encoding: encoding, headers: headers ) } }
Then ctrl-shift-f in your xcode project, search for sharedInstance.request or whatever you do to execute the requests (all my code follows this pattern) and replace it with sharedInstance.myRequest (do not change the extension of sharedInstance.request itself) and voila:
Globally modified custom header for all requests!
If you want to add custom keys, you can add methods using the replace method, for example sharedInstance.request (method: ...) to sharedInstance.myRequest (customKeys: ..., method: ...) if you need custom variables .
source share