forked from apollographql/apollo-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskData.swift
More file actions
38 lines (31 loc) · 990 Bytes
/
TaskData.swift
File metadata and controls
38 lines (31 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
/// A wrapper for data about a particular task handled by `URLSessionClient`
public class TaskData {
public let rawCompletion: URLSessionClient.RawCompletion?
public let completionBlock: URLSessionClient.Completion
private(set) var data: Data = Data()
private(set) var response: HTTPURLResponse? = nil
init(rawCompletion: URLSessionClient.RawCompletion?,
completionBlock: @escaping URLSessionClient.Completion) {
self.rawCompletion = rawCompletion
self.completionBlock = completionBlock
}
func append(additionalData: Data) {
self.data.append(additionalData)
}
func reset(data: Data?) {
guard let data, !data.isEmpty else {
self.data = Data()
return
}
self.data = data
}
func responseReceived(response: URLResponse) {
if let httpResponse = response as? HTTPURLResponse {
self.response = httpResponse
}
}
}