Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class APIClient {
- let urlSession = URLSession(configuration: .default)
- let notificationCenter = NotificationCenter.default
- func perform(_ urlRequest: URLRequest,
- completion: @escaping (Data?, URLResponse?, Error?) -> Void) {
- var urlSessionTask: URLSessionTask?
- urlSessionTask =
- urlSession
- .dataTask(with: urlRequest) { [weak self] (data, response, error) in
- completion(data, response, error)
- self?.notificationCenter
- .post(.makeURLSessionTaskNotification(urlSessionTask,
- urlSession: self?.urlSession,
- forName: .urlSessionTaskDidStart))
- }
- urlSessionTask?.resume()
- notificationCenter
- .post(.makeURLSessionTaskNotification(urlSessionTask,
- urlSession: urlSession,
- forName: .urlSessionTaskDidStart))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement