-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started migrating to a delegate based URLSession task system
- Loading branch information
Showing
2 changed files
with
61 additions
and
26 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Sources/TransloaditKit/TransloaditAPI+URLSessionDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
|
||
extension TransloaditAPI: URLSessionDelegate { | ||
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) { | ||
guard let callback = callbacks[task]?.1 else { | ||
return | ||
} | ||
|
||
if let error { | ||
callback(.failure(error)) | ||
return | ||
} | ||
|
||
guard let data = callbacks[task]?.0, let response = task.response else { | ||
//callback(.failure(TransloaditAPIError.unknown)) | ||
return | ||
} | ||
|
||
callback(.success((data, response))) | ||
} | ||
|
||
public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) { | ||
callbacks[dataTask]?.0?.append(data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters