SHARE
TWEET

Untitled

a guest Mar 20th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class APIClient {
  2.     let urlSession = URLSession(configuration: .default)
  3.     let notificationCenter = NotificationCenter.default
  4.    
  5.     func perform(_ urlRequest: URLRequest,
  6.                  completion: @escaping (Data?, URLResponse?, Error?) -> Void) {
  7.         var urlSessionTask: URLSessionTask?
  8.         urlSessionTask =
  9.             urlSession
  10.                 .dataTask(with: urlRequest) { [weak self] (data, response, error) in
  11.                     completion(data, response, error)
  12.                     self?.notificationCenter
  13.                         .post(.makeURLSessionTaskNotification(urlSessionTask,
  14.                                                               urlSession: self?.urlSession,
  15.                                                               forName: .urlSessionTaskDidStart))
  16.         }
  17.         urlSessionTask?.resume()
  18.         notificationCenter
  19.             .post(.makeURLSessionTaskNotification(urlSessionTask,
  20.                                                   urlSession: urlSession,
  21.                                                   forName: .urlSessionTaskDidStart))
  22.     }
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top