Reputation: 390
Let's say I have an array of Ints
let array = [1, 2, 3, 4, 5]
And let's say I also have a publish Relay that accepts Int elements
let relay = PublishRelay<Int>()
Is there a better way than to for loop over my array to stuff them into the relay?
for num in array {
relay.accept(num)
}
Upvotes: 1
Views: 379
Reputation: 33979
The Observable.from
operator is what you are looking for:
Observable.from(array)
.bind(to: relay)
Upvotes: 2