Skip to content

Instantly share code, notes, and snippets.

View asam139's full-sized avatar
🤤
Programming

Saúl Moreno Abril asam139

🤤
Programming
  • Granada, Spain
View GitHub Profile
@asam139
asam139 / Springboard.swift
Last active July 13, 2018 12:38 — forked from KoCMoHaBTa/- UITesting Utilities.md
UITesting Utilities
//
// Springboard.swift
// PriorityMatrixUITests
//
// Created by Saul Moreno Abril on 09/07/2018.
//
import Foundation
import XCTest
class Springboard {
@asam139
asam139 / swift-combine-retry.md
Created February 6, 2020 20:24 — forked from rdv0011/swift-combine-retry.md
Retry operation in Swift/Combine.

There is a function .retry() in Combine that helps to retry a request when something goes wrong with a long runing task. Although it is not enough just to call retry() to achieve retrying logic. The retry() function does not do another request but it re-subscribes only to a publisher. The below approaches might be used to solve the problem.

Using tryCatch

To make another request the tryCatch() might be used. In the code below if the first call fails there are three attempts to retry (retry(3)) that are made:

import UIKit
import Combine
import PlaygroundSupport

enum CustomNetworkingError: Error {
    case invalidServerResponse