Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.56 KB | None | 0 0
  1. //: Playground - noun: a place where people can play
  2.  
  3. import UIKit
  4.  
  5. class Test {
  6.     public var call: (() -> ())? = nil
  7.     public init() {
  8.         self.call = { [weak self] in
  9.             guard let `self` = self else { return print("No self") }
  10.             print(String(describing: self))
  11.         }
  12.     }
  13. }
  14.  
  15. var str = "Hello, playground"
  16. var test: Test? = Test()
  17. weak var test2 = test
  18. var call = (test?.call)!
  19.  
  20. test?.call?() ?? print("No Test instance")
  21. test = nil
  22. call() ?? print("No Test instance")
  23. test2?.call?() ?? print("No Test instance")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement