Group Group Group Group Group Group Group Group Group

Chapter 8: Collage - Clear Function fails

Loving the early release previews. In the Collage project, the clear function:
@IBAction func actionClear() {

…works perfectly when adding the single image.
However, as soon as you subscribe to the PhotoViewController, it no longer works
As far as i can tell emptying the array on images should work

It appears to be happening due to the completion sent down the publisher chain by the photos view controller in viewWillDisappear. At a guess, the images subject is responding to that by closing itself down, and no longer accepting inputs (or no longer passing them down the chain). Removing the line that sends the completion causes the app to work as advertised.

Interestingly, the subscribers just keep piling up. I’m not clear on whether they’ve even been cancelled.

1 Like

Hey, thanks both @robsnow68 @alanquatermain ! The reasoning, as you’ve guessed is that when using subscribe(images), the completion event is also sent through the current value (images) subject.

If you replace:



.assign(to: \.value, on: images)

You should be good to go :slight_smile:

We’ll make sure this is fixed in the final version of the book.