Quantcast
Channel: Combine: Asynchronous Programming with Swift - Kodeco Forums
Viewing all articles
Browse latest Browse all 26

How do i observe an Array when append or remove element with Combine?

$
0
0

When I adding or removing element in names array, no any result. following the code.
Could you give and advice?

class SomeClass: NSObject {
    @objc var names = ["A", "B", "C"]
    var cancellable: AnyCancellable?
    
    override init () {
        self.cancellable = names.publisher
            .sink { name in
                print("name: \(name)")
            }
    }
}

let someClass = SomeClass()
someClass.names.removeLast()

// === results ===
// name: A
// name: B
// name: C

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 26

Trending Articles