1

I have two objects Chat and messages both in Realm database. I am fetching from db and getting two observables. Message object have chatId through which I can get chat object. chats() - gives Observable<[Chat> messages() - gives Observable<[Messages>

The problem is when I use map function on messages(), I get chatId, now I need chat array to filter the chatId and get chat object.

How can I do that? Can I combine both observables and get emitted both array in single closure. If yes, then how?

Ankur Prakash
  • 1,417
  • 4
  • 18
  • 31

1 Answers1

1

Depending on the context, you want to use either combineLatest or withLatestFrom.

I don't quite understand the context because you say you have an Observable<[Message]>, but you are getting a single chatID from that array. I would expect you to get an array of chat IDs.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72
  • yes you are right. I did using combinedLatest. let combineObservable: Observable<([Chat], [Message])> = Observable.combineLatest(useCases.output.chats(), useCases.output.allMessages()) – Ankur Prakash Jul 23 '19 at 12:31