Swift Hipster
Swift Hipster

Reputation: 1664

RxSwift PublishSubject of type Optional<Any type> startWith nil

I'm trying to achieve the following:

let reachedTopMostMessage = PublishSubject<Int?>()
reachedTopMostMessage.startWith(nil).subscribeNext { (_) in
    //
}

But the compiler complains with this error:

'Int?' (aka 'Optional') is not convertible to '(Int?...)' (aka '(Optional...)')

What is wrong with this?

Upvotes: 1

Views: 725

Answers (1)

solidcell
solidcell

Reputation: 7729

Use Optional<Int>() to create a nil Int?, not just nil.

let reachedTopMostMessage = PublishSubject<Int?>()
reachedTopMostMessage.startWith(Optional<Int>()).subscribeNext { (_) in
    //
}

Upvotes: 2

Related Questions