ErrorHierarchy - A sibling framework to ActionHierarchy, but specialized for Error handling

Overview

Error Hierarchy

This is a sibling framework to ActionHierarchy, but specialized for Error handling.

Using a closure contained in EnvironmentValues, View objects that are lower in the hierarchy report Error objects up the view hierarchy, while views that are higher in the hierarchy use one of the modifiers to register themselves as a responder to receive, transform, or handle the Error objects.

Triggering an Error

Errors are triggered using the reportError closure added to EnvironmentValues.

Example:

struct MyError: Error {}

struct TriggerView: View {
	@Environment(\.reportError) var reportError
	
	var body: some View {
		Button("Trigger") {
			reportError(MyError())
		}
	}
}

Receiving, Handling and Transforming an Error

There are three kinds of operations that can be applied to an Error that has been triggered. All of these are executed by registering a closure the same way you would apply a view modifier to a View.

struct ContentView: View {
	var body: some View {
		TriggerView()
			.receiveError { .notHandled }
			.transformError { MyError() }
			.handleError {}
	}
}

All of these functions have a generic version that receives the type of an Error as the first parameter, only errors matching the provided type will be acted on, any other error will be propagated up the view hierarchy.

struct ContentView: View {
	var body: some View {
		TriggerView()
			.handleError(MyError.self) {}
	}
}

Receiving an Error

When receiving an Error, it's up to the registered closure to determine whether the Error has been fully handled or not.

If the registered closure returns .handled, the Error will no longer be propagated up the view hierarchy. If it returns .unhandled instead, the Error will continue to be propagated.

Handling an Error

Any error that is handled will no longer be propagated up the view hierarchy. This is equivalent to using a receiveError closure that always returns .handled.

Transforming an Error

Transforming functions can be used to replace the received Error. It could be an Error of a different type, or an Error of the same type but with different values.

You might also like...
An elegant pagination framework written in Swift.

Paginator Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation Paginato

IOS-IntegratedPhotoCapture - Integrated photo capture framework use podspec

IOS-IntegratedPhotoCapture integrated photo capture framework use podspec ======

LemonadeDeclarativeUI framework contains some new functions for UIKit

LemonadeDeclarativeUI framework contains some new functions for UIKit. This library has been developing. If you want to contribute reach me!

Using the UIKitChain framework, You can create a UIKit component in one line of code.
Using the UIKitChain framework, You can create a UIKit component in one line of code.

Using the UIKitChain framework, You can create a UIKit component in one line of code. Installation CocoaPods CocoaPods is a dependency manager for Coc

`SwiftUI` Framework  Learning and Usage Guide. 🚀
`SwiftUI` Framework Learning and Usage Guide. 🚀

This article refers to SwiftUI apple example and records the results of the exploration here, I hope to be helpful to you. For the content described i

🐵Fooling around with Apples private framework AvatarKit
🐵Fooling around with Apples private framework AvatarKit

Fooling around with Apples private framework AvatarKit, the framework used in Messages.app for recording Animoji videos. If you are looking to create your own Animoji, take a look at SBSCustomAnimoji.

A Set of Tools To Extend UIKit (Classic iOS Framework)
A Set of Tools To Extend UIKit (Classic iOS Framework)

RVS_UIKit_Toolbox A set of basic UIKit tools, for Swift iOS app development. Overview This package offers a few extensions of standard UIKit classes,

A iOS SwiftUI framework for displaying data from an api inside a List.

FeedListKit FeedListKit is a high level framework for representing data from an Api inside a SwiftUi List. It automatically handles refreshing and loa

Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling.

Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling. Greatly inspired by Argo, but without a bizillion

Test Library for Swift's Error Handling

CatchingFire CatchingFire is a Swift test framework, which helps making expectations against the error handling of your code. It provides for this pur

AsyncView is a SwiftUI View for handling in-progress and error states when loading data asynchronously.
AsyncView is a SwiftUI View for handling in-progress and error states when loading data asynchronously.

AsyncView AsyncView is a SwiftUI View for handling in-progress and error states when loading data asynchronously using async/await: See my blog post "

Protocol to handle initial Loadings, Empty Views and Error Handling in a ViewController & views
Protocol to handle initial Loadings, Empty Views and Error Handling in a ViewController & views

StatusProvider Protocol to handle initial Loadings, Empty Views and Error Handling in a ViewController & views CocoaPods Podfile pod 'StatusProvider'

straightforward networking and error handling with async-await and URLSession

AsyncAwaitNetworkingPlayground How To Run Just clone the project, open it and run. Some notes about AsyncAwaitNetworkingPlayground It's a straightforw

UI event handling using Apple's combine framework.
UI event handling using Apple's combine framework.

Description Combinative is a library for UI event handling using Apple's combine framework. It doesn't need many dependencies because it is written ma

iOS framework that enables detecting and handling voice commands using microphone.

iOS framework that enables detecting and handling voice commands using microphone. Built using Swift with minumum target iOS 14.3.

Placeholder views based on content, loading, error or empty states
Placeholder views based on content, loading, error or empty states

StatefulViewController A protocol to enable UIViewControllers or UIViews to present placeholder views based on content, loading, error or empty states

Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift
Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift

CDAlertView is highly customizable alert popup written in Swift. Usage is similar to UIAlertController. Screenshots Animations Usage Basic usage witho

DTTextField is a custom textfield with floating placeholder and error label
DTTextField is a custom textfield with floating placeholder and error label

DTTextField Introduction DTTextField is a UITextField library with floating placeholder and error label. Floating placeholder inspired from JVFloatLab

Gedatsu provide readable format about AutoLayout error console log
Gedatsu provide readable format about AutoLayout error console log

Gedatsu Gedatsu provide readable format about AutoLayout error console log Abstract At runtime Gedatsu hooks console log and formats it to human reada

Owner
Emilio Peláez
iOS Developer since 2009, sherlocked in 2011
Emilio Peláez
A compact but full-featured Auto Layout DSL for Swift

Mortar allows you to create Auto Layout constraints using concise, simple code statements. Use this: view1.m_right |=| view2.m_left - 12.0 Instead of:

Jason Fieldman 83 Jan 29, 2022
Powerful autolayout framework, that can manage UIView(NSView), CALayer and not rendered views. Not Apple Autolayout wrapper. Provides placeholders. Linux support.

CGLayout Powerful autolayout framework, that can manage UIView(NSView), CALayer and not rendered views. Has cross-hierarchy coordinate space. Implemen

Koryttsev Denis 45 Jun 28, 2022
A powerful Swift programmatic UI layout framework.

Build dynamic and beautiful user interfaces like a boss, with Swift. Neon is built around how user interfaces are naturally and intuitively designed.

Mike 4.6k Dec 26, 2022
Lightweight Swift framework for Apple's Auto-Layout

I am glad to share with you a lightweight Swift framework for Apple's Auto-Layout. It helps you write readable and compact UI code using simple API. A

null 349 Dec 20, 2022
Declarative iOS UI sugar framework built on FlexLayout

Declarative iOS UI sugar framework built on FlexLayout

당근마켓 97 Dec 9, 2022
Lightweight declarative auto-layout framework for Swift

SwiftyLayout SwiftyLayout is a framework that allows to describe layout constraints (ie NSLayoutConstraint) as a simple mathematical formula in a Swif

Hisakuni Fujimoto 15 Nov 7, 2017
A Swift binding framework

Bond, Swift Bond Update: Bond 7 has been released! Check out the migration guide to learn more about the update. Bond is a Swift binding framework tha

Declarative Hub 4.2k Dec 31, 2022
MyLayout is a simple and easy objective-c framework for iOS view layout

MyLayout is a powerful iOS UI framework implemented by Objective-C. It integrates the functions with Android Layout,iOS AutoLayout,SizeClass, HTML CSS float and flexbox and bootstrap. So you can use LinearLayout,RelativeLayout,FrameLayout,TableLayout,FlowLayout,FloatLayout,PathLayout,GridLayout,LayoutSizeClass to build your App 自动布局 UIView UITableView UICollectionView RTL

欧阳大哥2013 4.2k Dec 30, 2022
A declarative UI framework for iOS

Layout Layout is a native Swift framework for implementing iOS user interfaces using XML template files and runtime-evaluated expressions. It is inten

Nick Lockwood 2.2k Dec 23, 2022
FlightLayout is a light weight, and easy to learn layout framework as an extension of the UIView.

FlightLayout Introduction FlightLayout is a light weight, and easy to learn layout framework as an extension of the UIView. Functionally, it lives som

Anton 23 Apr 21, 2022