Disclaimer: I'm new to iOS programming, so this question is probably as simple as it looks. It's not a trick question!
I've a Swift project that uses Almofire to send HTTP requests. I want to add a parameter to the query string for every single request made.
So, I want to add mykey=myval
to every request.
- EG:
http://example.com/index -> http://example.com/index?mykey=myval
- EG:
http://example.com/index?key=val -> http://example.com/index?key=val&mykey=myval
I have found that all requests seem to go through
public func request(URLRequest: URLRequestConvertible) -> Request {
return Manager.sharedInstance.request(URLRequest.URLRequest)
}
in a file named Almofire.swift
and also through
public func request(URLRequest: URLRequestConvertible) -> Request {
var dataTask: NSURLSessionDataTask?
dispatch_sync(queue) {
dataTask = self.session.dataTaskWithRequest(URLRequest.URLRequest)
}
let request = Request(session: session, task: dataTask!)
delegate[request.delegate.task] = request.delegate
if startRequestsImmediately {
request.resume()
}
return request
}
in a file named Manager.swift, so I'm presuming I need to add a bit of code here. Due to my lack of Swift knowledge I've spend hours experimenting but no joy - only exceptions.
Does anyone know how I can add a parameter to all requests?