Chapter 10: When to use Observable vs Swift types

Hi,

I’m pretty much new with RxSwift and made it to chapter 10 so far. One thing that often confuses and and this may sound crazy, but it’s still not clear when to use Observable vs plain Swift objects. i.e.

let updatedCategoies = Observable
        .combineLatest(eoCategories, downloadedEvents) {
            (categories, events) -> [EOCategory] in
    }

Here, why didn’t we use Observable<[EOCategory]> but simple [EOCategory]. In my view, downloading both categories and events are asynchronous task and to me, Observable<[EOCategory]> would have made more sense.

Please explain me to core here. What’s the rule of thumb? Detailed explanation would be nice.

Thanks.

Hi @hassankhll,

I wrote a long answer to explain why, and then I just read chapter 10 on page 209, I believe it explains why this.

Just in case you are still looking and not convinced by the authors explanation, read on.

updatedCategory is the Observable of type [EOCategory]. The closure takes two params (from the signals being combined - categories and events) and returns an array of EOCategory.

if we were to declare the variable earlier, it would look like

let updatedCategories = Observable<[EOCategory]>

so we return a simple array of EOCategory. I hope that makes some sense and helps you understand this better.

cheers,

Jayant

This topic was automatically closed after 166 days. New replies are no longer allowed.