Combining Publishers, Subscribers, and Operators
In this section, we are going to mix the concepts of the previous section altogether in a real-world example feature. Let's assume that we have an app that contains a newsletter, and we allow the users to subscribe to the newsletter by entering their email address, using two UITextFields
: the Email and Repeat Email fields. Let's assume that in our business logic, we need to check that the email is correct, and we are going to do the following checks:
- Local check: We will ask users to repeat the email address twice, and both should be the same.
- Local check: The email should contain an "@".
- Local check: The email should be five characters long, at least.
- Remote check: We will also assume that we have a remote method to check in the backend that the email is unique, meaning it doesn't exist yet.
Once all these conditions match, we will enable a Sign-Up button in the user interface. We...