SHARE
TWEET

Untitled

a guest Mar 26th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class C {
  2.     lazy var x: () -> Void = {
  3.         return { print("hi") }
  4.     }()
  5.    
  6.     lazy var y: (Int) -> Void = { // `input in` shouldn't be written here!
  7.         return { input in
  8.             print(input)
  9.         }
  10.     }()
  11.    
  12.     var r: () -> Void = {
  13.         return { print("hi") }
  14.     }()
  15.    
  16.     let t: () -> Void = {
  17.         return { print("bye") }
  18.     }()
  19.    
  20.     let yy: (Int) -> Void = { // `input in` shouldn't be written here!
  21.         return { input in
  22.             print(input)
  23.         }
  24.     }()
  25. }
  26. let c = C()
  27. let k = c.x
  28.  
  29.  
  30. print(k) // (Function)
  31. k() // hi
  32. c.x() // hi
  33. c.y(5) // hi
  34. c.r()
  35. c.r = c.t
  36. print("new")
  37. c.r
  38. c.yy(10)
  39. c.yy(15) // Can pass different arguemnt
  40. c.t = c.r // Can't change the actual closure itself. It's a let. Needs to be changed to `var`
  41. c.t()
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