TupleResult - A micro library that easily converts tuple result into Swift.Result

Overview

TupleResult

A micro library that easily converts c-style tuple result into Swift.Result

In some cases, the result of the completion handler is returned in the form of response and error tuple. In Swift5 and later, Swift.Result makes writing code more intuitive. Using TupleResult, you can easily change the tuple result type to Swift.Result type.

Completion handler with response and error tuple

// Example

public func executeMethod(completion: (Response?, Error?) -> Void) {
    // when failure
    completion((nil, myError))

    // when success
    completion((myResponse, nil))
}

🧐 Before

import OtherModule

executeMethod { response, error in
    if let error = error {
        // handle failure
        return
    }

    guard let response = response else { return }

    // handle success
}

🚀 After

import TupleResult
import OtherModule

executeMethod {
    switch Result(success: $0, failure: $1) {
    case .success:
        // handle success(let success):
    case .failure(let failure):
        // handle failure
    }
}

💻 Installation

Swift Package Manager

  1. In Xcode, open your project and navigate to FileSwift PackagesAdd Package Dependency...
  2. Paste the repository URL (https://github.com/cozzin/TupleResult.git) and click Next.
  3. For Rules, select Branch (with branch set to master).
  4. Click Finish.
You might also like...
An Generic HTTP Request Library For Swift

GRequest An HTTP request library written in Swift. ##Basic Usage Be simple, as it should be: Request("https://api.github.com/repos/lingoer/SwiftyJSON/

Lightweight REST and JSON library for Swift.

RestEssentials is an extremely lightweight REST and JSON library for Swift and can be used on iOS, iPadOS, macOS, tvOS, and watchOS. Features Easily p

File downloading library for Swift 3
File downloading library for Swift 3

VeloxDownloader About: VeloxDownloader is an easy to use,elegant, native yet powerfull download library made with Swift 3. It abstracts all the comple

WebSocket(RFC-6455) library written using Swift

DNWebSocket Object-Oriented, Swift-style WebSocket Library (RFC 6455) for Swift-compatible Platforms. Tests Installation Requirements Usage Tests Conf

RSNetworking is a networking library written entirly for the Swift programming language.

RSNetworking is a networking library written entirly for the Swift programming language.

Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

Swift library for working with LSP

LanguageServerProtocol This is a Swift library for interacting with Language Server Protocol. It contains type definitions and utilities useful for bo

ServiceData is an HTTP networking library written in Swift which can download different types of data.

ServiceData Package Description : ServiceData is an HTTP networking library written in Swift which can download different types of data. Features List

A networking library for Swift
A networking library for Swift

Nikka Nikka is a super simple Swift HTTP networking library that comes with many extensions to make it modular and really powerful. Installation Usage

Releases(1.0.0)
Owner
Ernest SeongHo Hong
 iOS Developer
Ernest SeongHo Hong
An awesome Swift HTML DSL library using result builders.

SwiftHtml An awesome Swift HTML DSL library using result builders. let doc = Document(.html5) { Html { Head { Meta()

Binary Birds 204 Dec 25, 2022
Lazily deserialize JSON into strongly typed Swift objects

LazyObject Lazily deserialize JSON into strongly typed Swift objects, with a few getter style options. Is your app using it? Let me know! Installation

rob phillips 11 Nov 16, 2022
Communicate via HTTP easily in Swift.

swift-http-client Communicate via HTTP easily in Swift. Table of Contents Installation How to use Contribution Installation Swift Package Manager (Rec

null 14 Mar 1, 2022
SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN.

SwiftCANLib SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN. Th

Tim Wise 4 Oct 25, 2021
Easy to use OAuth 2 library for iOS, written in Swift.

Heimdallr Heimdallr is an OAuth 2.0 client specifically designed for easy usage. It currently supports the resource owner password credentials grant f

trivago N.V. 628 Oct 17, 2022
Swift based OAuth library for iOS

OAuthSwift Swift based OAuth library for iOS and macOS. Support OAuth1.0, OAuth2.0 Twitter, Flickr, Github, Instagram, Foursquare, Fitbit, Withings, L

OAuthSwift 3.1k Jan 6, 2023
🏇 A Swift HTTP / HTTPS networking library just incidentally execute on machines

Thus, programs must be written for people to read, and only incidentally for machines to execute. Harold Abelson, "Structure and Interpretation of Com

John Lui 845 Oct 30, 2022
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.

Why Zewo? • Support • Community • Contributing Zewo Zewo is a lightweight library for web applications in Swift. What sets Zewo apart? Zewo is not a w

Zewo 1.9k Dec 22, 2022
A lightweight library for writing HTTP web servers with Swift

Taylor Disclaimer: Not actively working on it anymore. You can check out some alternatives Swift 2.0 required. Working with Xcode 7.1. Disclaimer: It

Jorge Izquierdo 925 Nov 17, 2022
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022