CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | May 2015 |
SPMSupports SPM | ✗ |
Maintained by Daniel Perez.
A box implementation for Swift.
This is useful when some values can contain errors, for example when fetching some model from an API.
Add
pod 'SwiftBox'
to your PodFile.
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
}
}
}