Skip to content

Instantly share code, notes, and snippets.

@dmcyk
Created February 9, 2018 19:01
Show Gist options
  • Save dmcyk/b995c4cea1a72e9d90f75825af50c6f2 to your computer and use it in GitHub Desktop.
Save dmcyk/b995c4cea1a72e9d90f75825af50c6f2 to your computer and use it in GitHub Desktop.
import Foundation
class OtherObject {
var value: String = ""
deinit {
print("Other deinit")
}
}
class SomeClass {
var current = OtherObject()
var callback: ((String) -> [String])!
init() {
self.callback = { [weak self] value in
guard let current = self?.current else { return [] }
current.value += "\(value),"
return current.value.components(separatedBy: ",")
}
self.callback = { [current = self.current] value in
current.value += "\(value),"
return current.value.components(separatedBy: ",")
}
}
deinit {
print("Some deinit")
}
}
var some: SomeClass! = SomeClass()
some.callback("hi")
print(some.callback("bye"))
some = nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment