Home > AI > IOS > Combine >

assign(to:on:)

Example

1
2
3
4
5
6
7
8
9
10
11
class Demo {
    var anInt: Int = 0 {
        didSet {
            print("anInt was set to: \(anInt)", terminator: "; \n")
        }
    }
}
 
var myObject = Demo()
let cancellable = (0...2).publisher
    .assign(to: \.anInt, on: myObject)

Leave a Reply