Chapter 4: Observables and Subjects in Practice

Page no: 90
After Observing the sequence of selected photos, user can select as many photos from Library. To restrict user from selecting more than 6 photos, we can use take(6) while subscrtibing to selectedPhotos in MainViewController

photosViewController.selectedPhotos
        .take(6)
        .subscribe(onNext: { [weak self] newImage in
            guard let images = self?.images else {
                return
            }
            images.value.append(newImage)
            }, onDisposed: {
                print("completed photo selection")
        }).addDisposableTo(disposeBag)

I believe in the ideal world it makes sense to go with take(6). The suggested one will consider any tap on the collection view. If the user clicks the same picture 6 times (and if we need to prevent user selecting the same picture more than once as needed in the subsequent chapters) or to prevent the user on double tapping the picture etc.,

well, first of all let me say that since this is a piece of code from the very beginning of the book, some things could be rewritten much better but I’m intentionally using certain operators just to cover more ground :slight_smile: that said take(6) will just react to 6 events and if the user is tapping on the same photo all those taps will count towards the 6 limit, which as you see later in the chapter we won’t want for that project.