daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top