Latest 2.1.1
Homepage https://github.com/3squared/PeakResult
License Custom
Platforms ios 10.0
Authors

Peak Result

PeakResult is a Swift microframework providing a simple Result type. It is part of the Peak Framework.

The Result type is very simple: it represents either success, with an associated value representing the successful result; or a failure, with an associated error. This is perfect to represent operations which can potentially fail.

Examples

// Both are Result<String> even though one has a string and the other contains an error
let niceResult = Result { return "Hello!" }
let throwingResult = Result { throw TestError.justATest }

Unwrapping with switch-case

func throwingMethod() -> String throws { ... }
let result = Result { throwingMethod() }

switch result {
case .success(let value):
    print(value) // value is String
case .failure(let error):
    print(error.localizedDescription) // handle any error
}

Unwrapping with do-try

func throwingMethod() -> String throws { ... }
let result = Result { throwingMethod() }

do {
    let value = try result.resolve() // value is String
} catch {
    print(error.localizedDescription) // handle any error
}

Please see the included tests for further examples.

Getting Started

Installing

  • Using Cocoapods, add pod 'PeakResult' to your Podfile.
  • import PeakResult where necessary.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning.

License

This project is licensed under the MIT License – see the LICENSE.md file for details

Acknowledgments

Peak Framework

The Peak Framework is a collection of open-source microframeworks created by the team at 3Squared, named for the Peak District. It is made up of:

Name Description
PeakOperation Provides enhancement and conveniences to Operation, making use of the Result type.
PeakNetwork A networking framework built on top of Session using PeakOperation, leveraging the power of Codable.

Latest podspec

{
    "name": "PeakResult",
    "version": "2.1.1",
    "summary": "An enum that contains a result.",
    "homepage": "https://github.com/3squared/PeakResult",
    "license": {
        "type": "Custom",
        "file": "LICENSE.md"
    },
    "authors": {
        "Sam Oakley": "[email protected]"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/3squared/PeakResult.git",
        "tag": "2.1.1"
    },
    "source_files": [
        "PeakResult",
        "PeakResult/**/*.{h,m,swift}"
    ],
    "swift_version": "4.2"
}

Pin It on Pinterest

Share This