CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.

SwiftBox 0.1.2

SwiftBox 0.1.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release May 2015
SPMSupports SPM

Maintained by Daniel Perez.



SwiftBox 0.1.2

  • By
  • Claude Tech

Swift box implementation

A box implementation for Swift.

This is useful when some values can contain errors, for example when fetching some model from an API.

Installation

Add

pod 'SwiftBox'

to your PodFile.

Example

public class User {
    var name: String

    init(_ name: String) {
        self.name = name
    }
}

public class MyClass {
    var user: Box<User>

    init() {
        self.user = Box.Empty
    }

    func showUser(u: User) {
        // do something
    }

    func handleError(err: NSError) {
        // handle your error
    }

    func tryShowUser() {
        switch user {
        case Box.Full(let u):
            showUser(u.v)
        case Box.Failure(let err):
            handleError(err)
        case Box.Empty:
            break
        }
    }
}