-
-
Save hasancanakgunduz/48d427957f7b422be1f6af1a3cf3ff25 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
class WeakBox<T: AnyObject> { | |
weak var value: T? | |
init(_ value: T) { | |
self.value = value | |
} | |
} | |
class Subscriber { | |
let publisher: Publisher | |
init(publisher: Publisher) { | |
self.publisher = publisher | |
} | |
deinit { | |
print("Subscriber deinit") | |
} | |
} | |
class Publisher { | |
var subscribers: [WeakBox<Subscriber>] = [] | |
deinit { | |
print("Publisher deinit") | |
} | |
} | |
do { | |
let publisher = Publisher() | |
let subscriber = Subscriber(publisher: publisher) | |
publisher.subscribers.append(WeakBox(subscriber)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment