Created
February 9, 2018 19:01
-
-
Save dmcyk/b995c4cea1a72e9d90f75825af50c6f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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