Created
May 13, 2022 21:28
-
-
Save taichino/479ae77c15bd68ca6fbd871fe4badb30 to your computer and use it in GitHub Desktop.
Observing an array test
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 Combine | |
var list = ["A", "B", "C"] | |
let cancellable = list.publisher | |
.collect() | |
.sink { completion in | |
print("Completed with \(completion)") | |
} receiveValue: { value in | |
print(value) | |
} | |
print("@@ start mutating list @@") | |
list.append("D") | |
list.removeAll { $0 == "B"} | |
print(cancellable) | |
// output looks like the following. | |
// --- | |
// ["A", "B", "C"] | |
// Completed with finished | |
// @@ start mutating list @@ | |
// Combine.AnyCancellable | |
// --- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment