Chapter 4 how to use the custom alert observable

Hey, great reading so far.
I’ve written my custom Rx alert view controller extension and removed the previous UIKit related showMessage(_:description:) code.

How does the original block of code that calls the show methods inside the actionSave function change now that the showMessage method returns an observable while also integrating that with the events emitted by PhotoWriter?

    @IBAction func actionSave() {
        guard let image = imagePreview.image else { return }
        PhotoWriter.save(image)
            .subscribe(
                onError: { [weak self] error in
                self?.showMessage("Error", description: error.localizedDescription)
            },
                onCompleted: { [weak self] in
                    self?.showMessage("Saved")
                    self?.actionClear()
            })
        .disposed(by: self.disposeBag)
    }

Hey! I’ve invited @icanzilb (the author of this chapter) to the discussion as hopefully he will be able to help you with your question! Good luck :slight_smile:

Alright, I look forward to the response, the sooner the better as I don’t want to get too ahead.
Thank you

Pavan

Hey, if you get stuck implementing the challenge just peak in the provided solution - it’s located in the “challenge” folder of Chapter 4

@icanzilb That’s precisely what I did in the hopes I could see how that newly created custom alert+rx observable would have been implemented and subscribed to but instead the code just uses the default original showMessage function rather than using the returned observable to subscribe to.

well, showing an alert on screen is a side effect - I personally would have it in a separate method

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