Guest User

Untitled

a guest
Dec 15th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. extension GenericClass where T: OptionalType {
  2. func valueOrThrow() throws -> T.Wrapped {
  3. if let unwrapped = self.value.value {
  4. return unwrapped
  5. }
  6.  
  7. throw ErrorImpl("No value found")
  8. }
  9. }
  10.  
  11. func testGenericClass() {
  12. let gc1 = GenericClass<Int>(1)
  13. // gc1.valueOrThrow() - does not compile.
  14.  
  15. let gc2 = GenericClass<Int?>(1)
  16.  
  17. do {
  18. let value = try gc2.valueOrThrow() // This is of type Int
  19. } catch let e {
  20. ...
  21. }
  22. }
Add Comment
Please, Sign In to add comment