Group Group Group Group Group Group Group Group Group

Please explain when to use asObservable() in Chapter 4, page 90

In Chapter 4, page 90, these lines of code:

images.asObservable()
.subscribe(onNext: { [weak self] photos in
self?.updateUI(photos: photos)
})
.disposed(by: bag)

as Observable() is not explained. On Page 89, asObservable() is not called with this code:

images
.subscribe(onNext: { [weak imagePreview] photos in
guard let preview = imagePreview else { return }
preview.image = photos.collage(size: preview.frame.size)
})
.disposed(by: bag)

Please explain when to use .asObservable() and when to subscribe use the Relay itself.

Thanks,
Mike

2 Likes

Hey guys! I’ve just came with the same question… The example on page 90 has the asObservable call, but looks like the behaviour is the same as without this call. Could you specify please why exactly should we use or not this call? (asObservable)
Thanks!

Hi guys… I’m having the same question (same on page 94 too).
Can someone answer this question for us?

Hi @mike ,

Regardless if the code works with or without .asObservable() seems that the intention to use it is to make clear to the user that only changes in self.images are being observed and nothing else

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