Skip to content

Instantly share code, notes, and snippets.

@olbrichj
Created March 21, 2018 10:28
Show Gist options
  • Save olbrichj/9034a7c4635a4e2866aba5ffebc2ef79 to your computer and use it in GitHub Desktop.
Save olbrichj/9034a7c4635a4e2866aba5ffebc2ef79 to your computer and use it in GitHub Desktop.
public class ApiRequestDelegate:NSObject, URLSessionDelegate, URLSessionTaskDelegate,
URLSessionDataDelegate{
// called once as soon as a response returns
public func urlSession(session: URLSession, dataTask: URLSessionDataTask,
didReceiveResponse response: URLResponse,
completionHandler: (URLSession.ResponseDisposition) -> Void) {
// store Response to further process it and call completion Handler to continue
}
// called when finished
public func urlSession(session: URLSession, task: URLSessionTask,
didCompleteWithError error: NSError?) {
// handle errors and e.g. call a completion handler so you can continue with your tasks or start a different request
}
// called if data is not returned in one block
public func urlSession(_: URLSession, dataTask: URLSessionDataTask,
didReceive data: NSData) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment