Latest 2.2.1
License Custom
Platforms ios 10.0, tvos 10.0, osx 10.13

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.


// 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


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


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


We use SemVer for versioning.


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


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
PeakCoreData Provides enhances and conveniences to Core Data.
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.2.1",
    "summary": "An enum that contains a result.",
    "homepage": "",
    "license": {
        "type": "Custom",
        "file": ""
    "authors": {
        "Sam Oakley": "[email protected]"
    "source": {
        "git": "",
        "tag": "2.2.1"
    "swift_version": "4.2",
    "platforms": {
        "ios": "10.0",
        "tvos": "10.0",
        "osx": "10.13"
    "source_files": [
    "ios": {
        "source_files": "PeakResult/Platforms/iOS/**/*.{h,m,swift}"
    "tvos": {
        "source_files": "PeakResult/Platforms/iOS/**/*.{h,m,swift}"
    "osx": {
        "source_files": "PeakResult/Platforms/macOS/**/*.{h,m,swift}"

Pin It on Pinterest

Share This