Latest 0.2.1
License MIT
Platforms ios 8.0

CI Status
Swift v4

What is this?

A small library which simplifies error handling code in your view controllers/view models by using Chain of Responsibility pattern. It also allows you to reuse error handling code if you need the same behavior in another project.

How it works?

One of the main things here are so called "proposers". Every proposer usually takes one specific type of error as an input and proposes method to handle this error – for example, "Show a system alert", or passes this error down by hierarchy. Executing this method(e.g. showing a system alert) is completely up to you.

Handling your own custom errors is pretty simple – create a class which implements MethodProposing protocol and return correct "proposition" for your errors:

enum MyCustomError: Swift.Error {
    case somethingBadHappened

class MyProposer: MethodProposing {
    func proposeMethod(toHandle error: Error) -> Proposition? {
        guard let myCustomError = error as? MyCustomError else {
            return nil

        let config = SystemAlertConfiguration(
            title: "Error",
            message: "Oops! Something went wrong",
            actionTitle: "OK"

        return .single(.systemAlert(config))

Then you can pass this proposer to ErrorDispatcher initializator, as well as any other proposers you need:

let compoundProposer = CompoundMethodProposer(proposers: [
let dispatcher: ErrorDispatcher = ErrorDispatcher(proposer: compoundProposer)

To execute proposed methods, you should implement MethodExecutor protocol. This is a callback which will be called when dispatcher found a "method" to handle this error. Example:

extension ExampleViewController: MethodExecutor {
    func execute(method: ErrorHandlingMethod) {
        switch method {
        case .systemAlert(let config):
            showSystemAlert(with: config)

After that you can use ErrorDispatcher to handle your errors as following:

dispatcher.executor = self

let nsError = NSError(domain: NSURLErrorDomain, code: NSURLErrorCannotFindHost, userInfo: nil)
dispatcher.handle(error: nsError)


Just launch Example/ErrorDispatching.xcworkspace, build and run. Cocoapods are already installed.


ErrorDispatching is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "ErrorDispatching"


Swift Version Pod Version
3.0 0.1.3+
4.0 0.2.0+


  • Add more built-in proposers for system errors
  • More localizations as well


Anatoliy Radchenko, [email protected]


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

Latest podspec

    "name": "ErrorDispatching",
    "version": "0.2.1",
    "summary": "A simple and reusable error handling in Swift",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Anatoliy Radchenko": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.2.1"
    "platforms": {
        "ios": "8.0"
    "default_subspecs": "Core",
    "pushed_with_swift_version": "4.0",
    "subspecs": [
            "name": "Core",
            "source_files": "ErrorDispatching/Classes/Core/**/*",
            "frameworks": [
            "resource_bundles": {
                "ErrorDispatching": [
            "name": "ReactiveSwift",
            "source_files": "ErrorDispatching/Classes/ReactiveSwift/**/*",
            "dependencies": {
                "ErrorDispatching/Core": [],
                "ReactiveSwift": [
                    "~> 3.0"
                "Result": [
                    "~> 3.0"
            "name": "Moya",
            "source_files": "ErrorDispatching/Classes/Moya/**/*",
            "dependencies": {
                "ErrorDispatching/Core": [],
                "Moya": [
                    "~> 11.0.0-beta.1"

Pin It on Pinterest

Share This