The problem is that the Output
of future
is Int
, so you cannot replace errors with nil
, you'd need to replace them with an Int
, since the Output
of upstream publishers and the input of downstream operators must always match.
You can resolve the issue by mapping the future
's Output
to Optional<Int>
, then you can replace errors with nil
.
future
.receive(on: RunLoop.main)
.map(Optional.some)
.replaceError(with: nil)
.assign(to: &$count)
Also, assign(to:)
takes a Published.Publisher
as its input, so you need to make your count
@Published
and pass in its Publisher
using $count
to assign
.
So change the declaration to @Publised var count: Int? = 0
.