A Callbag sinker that will assign the latest next event value to a
Class
orStruct
. And it returns aCancellable
.
Examples
assign to variable in class:
class MyClass {
var element: Int = 0
}
var myClass = MyClass()
_ = just(1)
|> assign(to: \.element, on: myClass)
print(myClass.element) // 1
assign to variable in struct:
struct MyStruct {
var element: Int = 0
}
var myStruct = MyStruct()
_ = just(1)
|> assign(to: \.element, on: &myStruct)
print(myStruct.element)
assign to struct/class:
var element: Int = 0
_ = just(1)
|> assign(to: &element)
print(element)