Skip to content

Instantly share code, notes, and snippets.

@rustle
Last active November 25, 2019 21:43
Show Gist options
  • Save rustle/10e23530556d332b7d5ca2733a204a0b to your computer and use it in GitHub Desktop.
Save rustle/10e23530556d332b7d5ca2733a204a0b to your computer and use it in GitHub Desktop.
import Foundation
/*
Somewhere in Foundation
public protocol Foo {
...
public init<T>?(foo value: T) where T: Foo
...
}
*/
extension Foo {
init<T>(foo value: T) throws where T: Foo {
guard let f = Self(foo: value) else {
throw FooError.noap
}
self = f
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment