Home > AI > IOS > Combine >

assign(to:on:)

Example

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