💊 Syntactic sugar for Swift do-try-catch

Overview

Fallback

Swift Build Status CocoaPods Carthage compatible

Syntactic sugar for Swift do-try-catch.

At a Glance

value = try fallback(
  try get("A"),
  try get("B"),
  try get("C"),
  try get("D")
)

is equivalent to:

do {
  value = try get("A")
} catch {
  do {
    value = try get("B")
  } catch {
    do {
      value = try get("C")
    } catch {
      value = try get("D")
    }
  }
}

Installation

  • Using CocoaPods:

    pod 'Fallback', '~> 0.2'
  • Using Carthage:

    github "devxoul/Fallback" ~> 0.2
    
  • Using Swift Package Manager:

    import PackageDescription
    
    let package = Package(
      name: "MyAwesomeProject",
      targets: [],
      dependencies: [
        .Package(url: "https://github.com/devxoul/Fallback.git", majorVersion: 0)
      ]
    )

License

Fallback is under MIT license. See the LICENSE file for more info.

You might also like...
Aplicação Basica em Swift desenvolvida com o intuito de aplicar os conceitos estudados
Aplicação Basica em Swift desenvolvida com o intuito de aplicar os conceitos estudados

Via Cep iOS Sobre - Interface do Usuario - Tecnologias - Requisitos - Autor Projeto 🛑 FINALIZADO 🛑 Sobre A Aplicação consiste em fazer buscas usando

Haven't you wished for `try` to sometimes try a little harder? Meet `retry`

Retry Example Haven't you wished for try to sometimes try a little harder? Meet retry To run the example project, clone the repo, and run pod install

Sweet-swift - Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper Functions and Common Utilities

Sweet Swift Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper F

Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch

Async Now more than syntactic sugar for asynchronous dispatches in Grand Central Dispatch (GCD) in Swift Async sugar looks like this: Async.userInitia

✨ Super sweet syntactic sugar for Swift initializers

Then ✨ Super sweet syntactic sugar for Swift initializers. At a Glance Initialize UILabel then set its properties. let label = UILabel().then { $0.t

Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch (iOS7+ and OS X 10.9+ compatible)

Async.legacy Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch (GCD) Async rewritten for iOS7 and OS X 10.9 Compatibility

Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch

Async Now more than syntactic sugar for asynchronous dispatches in Grand Central Dispatch (GCD) in Swift Async sugar looks like this: Async.userInitia

And - Syntactic sugar for Swift initializers

And Syntactic sugar for Swift initializers Usage let label = UILabel().and { $0

TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use.
TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use.

TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use. Features Pure Swift 5 sweetness. Everything you can do with Auto

✨ Super sweet syntactic sugar for SwiftUI.View initializers.

ViewCondition ✨ Super sweet syntactic sugar for SwiftUI.View initializers. At a Glance struct BorderTextView: View { var color: Color? @ViewBuild

Syntactic Sugar for Accelerate/vImage and Core Image Filters
Syntactic Sugar for Accelerate/vImage and Core Image Filters

ShinpuruImage Syntactic Sugar for Accelerate/vImage and Core Image Filters ShinpuruImage offers developers a consistent and strongly typed interface t

🍯 Syntactic sugar for Moya

MoyaSugar Syntactic sugar for Moya. Why? Moya is an elegant network abstraction layer which abstracts API endpoints gracefully with enum. However, it

Shadow - Syntactic sugar for shadows in the SwiftUI framework

Shadow Syntactic sugar for shadows in the SwiftUI framework. import SwiftUI impo

Swift's Sugar. Heavily inspired on Objc Sugar

Swift's Sugar. Heavily inspired on Objc Sugar

Catch Objective-C exceptions in Swift

ExceptionCatcher Catch Objective-C exceptions in Swift There are many Cocoa APIs that can throw exceptions that cannot be caught in Swift (NSKeyedUnar

This library uses ARKit Face Tracking in order to catch user's smile.
This library uses ARKit Face Tracking in order to catch user's smile.

SmileToUnlock Make your users smile before opening the app :) Gif with the demonstration Installation Cocoapods The most preferable way to use this li

A Codable extension to decode arrays and to catch & log all decoding failures
A Codable extension to decode arrays and to catch & log all decoding failures

SafeDecoder A Codable extension to decode arrays and to catch & log all decoding failures Features SafeDecoder makes two improvements for Codable mode

try! Swift Tokyo
try! Swift Tokyo

trySwiftApp try! Swift Conference App try! Swift Presentations You can find an overview of speakers and their presentations, including slides and vide

🎉 WWDC 2021 Swift Student Challenge Winner 🎉 Dance Party allows users to record choreography and play against other users to try and match the key poses!
🎉 WWDC 2021 Swift Student Challenge Winner 🎉 Dance Party allows users to record choreography and play against other users to try and match the key poses!

💃 Dance Party 🕺 🍎 WWDC 2021 Swift Student Challenge Winner 🎉 Installation Steps (Works on iPad Only) Clone or Download Unzip the .playgroundbook.z

Comments
  • Add support chaining

    Add support chaining

    This is for whom wants handle each errors.

    From the comment from Reddit:

    Keeps it short and sweet. My biggest concern is that it's limiting errors to control flow. If get("A") and get("B") fail and we get("C") instead, what happened to the errors from the previous 2 calls? It looks to me like it only throws the last error.

    Examples

    let value: String = fallback {
      return try get("a")
    }.catch { error in // error from "a"
      return try get("b")
    }.catch { error in // error from "b"
      return try get("c")
    }.finally { error in // error from "c"
      return "none"
    }
    print(value) // "none"
    
    let value: String = try fallback {
      return try get("a")
    }.catch { error in // error from "a"
      return try get("b")
    }.catch { error in // error from "b"
      return try get("c")
    }.rethrow() // will throw error from "c"
    

    To Do

    • [x] Implement
    • [x] Test
    • [ ] Documentation
    opened by devxoul 0
Releases(0.2.0)
Owner
Suyeol Jeon
A lazy developer 😴 I write many code to write less code.
Suyeol Jeon
A tool for Swift code modification intermediating between code generation and formatting.

swift-mod A tool for Swift code modification intermediating between code generation and formatting. Overview swift-mod is a tool for Swift code modifi

Ryo Aoyama 95 Nov 3, 2022
SwiftCop is a validation library fully written in Swift and inspired by the clarity of Ruby On Rails Active Record validations.

SwiftCop is a validation library fully written in Swift and inspired by the clarity of Ruby On Rails Active Record validations. Objective Build a stan

Andres Canal 542 Sep 17, 2022
A command-line tool and Xcode Extension for formatting Swift code

Table of Contents What? Why? How? Command-line tool Xcode source editor extension Xcode build phase Via Applescript VSCode plugin Sublime Text plugin

Nick Lockwood 6.3k Jan 8, 2023
A tool to enforce Swift style and conventions.

SwiftLint A tool to enforce Swift style and conventions, loosely based on the now archived GitHub Swift Style Guide. SwiftLint enforces the style guid

Realm 16.9k Jan 9, 2023
An Xcode formatter plug-in to format your swift code.

Swimat Swimat is an Xcode plug-in to format your Swift code. Preview Installation There are three way to install. Install via homebrew-cask # Homebrew

Jintin 1.6k Jan 7, 2023
Cross-platform static analyzer and linter for Swift.

Wiki • Installation • Usage • Features • Developers • License Tailor is a cross-platform static analysis and lint tool for source code written in Appl

Sleekbyte 1.4k Dec 19, 2022
Type-safe observable values and collections in Swift

GlueKit ⚠️ WARNING ⚠️ This project is in a prerelease state. There is active work going on that will result in API changes that can/will break code wh

null 361 Oct 12, 2022
A Swift micro-framework to easily deal with weak references to self inside closures

WeakableSelf Context Closures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the refe

Vincent Pradeilles 72 Sep 1, 2022
Measure Swift code metrics and get reports in Xcode, Jenkins and other CI platforms.

Taylor ⚠️ Taylor is DEPRECATED. Use SwiftLint instead. A tool aimed to increase Swift code quality, by checking for conformance to code metrics. Taylo

YOPESO 301 Dec 24, 2022
Swift-lint-plugin - A SwiftPM plugin that adds a linting command

SwiftLintPlugin This is a SwiftPM plugin that adds a lint command. SwiftPM plugi

null 9 Nov 23, 2022