How to use Combine sinks #244
-
I do not open the bug part because the problem may not be related to the library.
Can anyone help with this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @murataksu740, First you're not retaining your sink. Your other mistake is that in init() {
getUser()
$current.sink { print($0) }.store(in: &bin)
}
func getUser() {
guard let secret = self.secret.value else { return }
// Fetch the user.
Endpoint.user(secret.identifier)
.unlock(with: secret)
.session(.instagram)
.map(\.user)
.catch { _ in Just(nil) }
.receive(on: RunLoop.main)
.assign(to: \.current, on: self)
.store(in: &bin)
} You tried to adapt the code in the Followers example without actually capturing what was going on. |
Beta Was this translation helpful? Give feedback.
Hey @murataksu740,
.
No bugs, your code is just faulty.
First you're not retaining your sink.
You should
store(in: &bin)
that too instead of discarding the result with_ =
.Your other mistake is that in
getUser
the publisher only starts streaming whensecret
changes, not when you actually call it.You tried to adapt th…