Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension GenericClass where T: OptionalType {
- func valueOrThrow() throws -> T.Wrapped {
- if let unwrapped = self.value.value {
- return unwrapped
- }
- throw ErrorImpl("No value found")
- }
- }
- func testGenericClass() {
- let gc1 = GenericClass<Int>(1)
- // gc1.valueOrThrow() - does not compile.
- let gc2 = GenericClass<Int?>(1)
- do {
- let value = try gc2.valueOrThrow() // This is of type Int
- } catch let e {
- ...
- }
- }
Add Comment
Please, Sign In to add comment