Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement