Michael Long
1 min readOct 20, 2019

--

In one of the later betas Combine added a “disposeBag” mechanism with a type-erased AnyCancellable that automatically deinits.

var subscriptions = Set<AnyCancellable>()somePublisher
.sink(receiveValue: { data in
...
})
.store(in: &subscriptions)

Builder mechanism is nice, though. Could add it as an extension to Set where type is AnyCancellable.

Though, come to think of it…

subscriptions.formUnion([
p.sink(receiveValue: { print($0) }),
p.sink(receiveValue: { print($0) })
])

Appreciated the link back, btw.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)