RxSwift convert Observable<Bool> to Observable<Void>

biloshkurskyi.ss picture biloshkurskyi.ss · Aug 17, 2017 · Viewed 8.4k times · Source

I am not so convinced with RxSwift yet, and it's really hard to cleat understanding. After reviewing different materials, I cant' still work and manipulate sequences. On the whole I have problem with type converting:

Cannot convert return expression of type 'Observable<Bool>' to return type 'Observable<Void>' (aka 'Observable<()>')    

I have CocoaAction processing, and should return Observable<Void>

func stopProject() -> CocoaAction {
    return CocoaAction { _ in
        let stopProject = stop(project: self.projectId)
        return stopProject.asObservable() //wrong converting
    }
}

The stop function return Observable<Bool>

Finish view:

    return stop(project: self.projectId).flatMap { _ in
        Observable<Void>.empty()
    }

Answer

Maxim Volgin picture Maxim Volgin · Aug 17, 2017
let voidObservable = boolObservable.map { Void() }