← All projects

DMAction Swift SDK

Type
Open-source Swift SDK
Period
01/2024 – present
public since 02/2025
Platforms
iOS 17+, watchOS 7+
UI
SwiftUI, UIKit
Install
Swift Package Manager, CocoaPods
License
MIT
Source
GitHub
DMAction: action, retry, and fallback

Overview

DMAction is a Swift library for composing completion-based actions with retry and fallback behavior. It centralizes execution and result handling behind a protocol-oriented API shared by UIKit and SwiftUI clients.

Key features

  • Compose actions with configurable retry and fallback behavior.
  • Receive asynchronous results through completion handlers.
  • Ignore results through simpleAction or handle them through Result.
  • Use the same small API from UIKit and SwiftUI.

Example

This example allows one retry after the primary action’s initial attempt. If both attempts fail, DMAction invokes the fallback action.

import Foundation
import DMAction

let primaryButtonAction = DMButtonAction { completion in
    completion(.failure(NSError(domain: "TestError", code: 1, userInfo: nil)))
}

let fallbackButtonAction = DMButtonAction { completion in
    completion(.success("Fallback succeeded"))
}

let actionWithFallback = primaryButtonAction
    .retry(1)
    .fallbackTo(fallbackButtonAction)

actionWithFallback { result in
    switch result.unwrapValue() {
    case .success(let value):
        print("Result value: \(value)")
    case .failure(let error):
        print("Action failed: \(error)")
    }
}

Installation

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/nikolay-dementiev/DMAction.git", from: "1.0.5")
]

CocoaPods:

pod 'DMAction'

Links