Code Block Swiftself.cancelable = URLSession.shared.dataTaskPublisher(for: self.chartRequest.asRequest()) |
|
.retry(3) |
|
.subscribe(on: DispatchQueue.global()) |
|
.map({ $0.data }) |
|
.decode(type: [ChartEntry].self, decoder: JSONDecoder()) |
|
.map({ data in return .success(data) }) |
|
.catch({ result in |
|
return Just.init(.failure(result)) |
|
}) |
|
.receive(on: RunLoop.main) |
|
.sink(receiveCompletion: { (_) in |
|
print("receiveCompletion") |
|
}, receiveValue: { (data: Result) in |
|
|
|
switch data { |
|
case .success(let entries): |
|
self.tickerResultJsonCount = entries.count |
|
self.entries = entries.first?.data ?? [] |
|
case .failure(let error): |
|
self.entries = [] |
|
self.tickerResultJsonCount = 0 |
|
self.error = error |
|
} |
|
|
|
}) |
my code is like this