Advertisement
wpl36

Untitled

Jun 30th, 2021
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. //
  2. // main.swift
  3. // CMDTool
  4. //
  5. // Created by Ivanov Ivan on 30.06.2021.
  6. //
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. //
  14. //var x = "a"
  15. //
  16. //let closure = { [x] () -> () in
  17. // print(x)
  18. //}
  19. //
  20. //closure()
  21. //
  22. //x = "b"
  23. //
  24. //closure()
  25. //
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. import Foundation
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. let firstScope = true
  60.  
  61.  
  62. class Person {
  63. var dog: Dog?
  64. var closure2: (() -> ())?
  65.  
  66.  
  67. init() {
  68. dog = Dog(person: self)
  69. }
  70.  
  71. deinit {
  72. print("person is free")
  73. }
  74. }
  75.  
  76.  
  77. class Dog {
  78. unowned var person: Person
  79.  
  80. init(person: Person){
  81. self.person = person
  82. }
  83. deinit {
  84. print("dog is free")
  85. }
  86. }
  87.  
  88. let closure1: () -> ()?
  89.  
  90. //------------------FIRST-------------------------------------
  91. if firstScope {
  92. print("firstScope has STARTED<--------<--------1")
  93.  
  94. let person = Person()
  95. let dog = person.dog
  96.  
  97. closure1 = {[dog] in
  98. print(dog)
  99. }
  100.  
  101.  
  102. print("firstScope has ENDED-------->-------->1")
  103. }
  104. //------------------FIRST ENDS---------------------------------
  105.  
  106.  
  107. print("THE END")
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement