Right, so let's look at how we in or actually register all the buttons are set up, all the methods,
fire is just up to us to implement the firebase code.
So to do this, of course, we need, first of all, firebase off.
And then when the in is tapped, we need a way to see what the log in or to pass over those email and
password to Firebase.
Now, the first thing we need to do, of course, is double check that the following is true.
That's not empty and that's not empty, because if they are empty, we shouldn't bother making a call
to Firebase because all these calls add up to fees we might have to pay.
So what we're going to do is make sure we don't make a call unless the email and the password look legit.
OK, so what I'm going to do is create a function down here called check input or validate input or
whatever you want to call it.
And then I'm going to return a bool on this.
So maybe we'll call it the input valid.
That's a more that's a better name.
And then we'll say if input valid and if it's not valid.
So we're going to put an exclamation then for now we're going to return.
Of course, we can also show an error to the user.
We can show the error down here so we don't have to repeat the code, of course.
OK, of course, I've been playing with Colin and things like that a lot, so I always forget to put
these in.
So I'm going to copy that and I'm going to put it in register.
I'm going to forget about, forgot about, because I'm not quite sure how we're going to do that flow
when we get to that point.
So input valid?
Well, first of all, we have to get the email input text and we also need to get the password input
dot text.
Now, these are optional as in the text might not exist, but at least I thought they were optional.
Let's see what happens.
No, I think they're perfectly fine.
So let's have a let email equal and let password equal.
OK, so we have the text from those so we can do a very basic validation here.
See, they are optional.
OK, so if email account, what we're doing is accounting a number of characters is less than, let's
say for an email address, you need at least four characters because it's something at something dot
com, actually, five characters or six, rather.
So if it's that or if pass don't count is less, then I don't know, let's say five characters, then
we're also going to kick the user out.
So we're going to say return false.
And at this point we can actually show the user an error.
OK, so this email is giving us errors.
So what I'm going to do is just put an exclamation after these options because I know that the text
exists.
Even if there is nothing in the box, the text itself will exist.
So this is one of those rare cases where you can actually force unwrap the optional again, if you don't
remember what options are they?
Just a box that might contain the type of value you specify or might contain nothing.
Go back to my old courses on Swift, my previous courses, I should say.
They will explain all of that stuff for you.
Otherwise we are going to return.
True.
OK, so that's the validation of the input sorted later on, perhaps we can well, why?
Why later on?
Let us create a new file and let's do it now.
Swift file.
Utilities, my favorite kind of thing, so let's import the UI kit.
And call this what it should be.
Don't need to inherit anything, and then we have some code, so function show alert.
Now, let me see how I've done this in my previous project, because there's no point in dragging you
guys through this.
OK, I'm trying to copy this and I'll talk you through why it's doing what it's doing there.
So to show the alert, we need to have access to The View controller because the View controller contains
the navigation controller that will allow us to display the alert, as in we need a reference to The
View.
OK, so that's what we're pulling in there.
If you didn't do that, there are other ways of architecting this where you could have your utility
class access to The View, but we're not going to do anything complex here.
Then we have an alert.
We have an action which is OK, and we're just going to pass over the title and message.
So this is generic.
Finally, we're going to present that particular view controller.
Feel free to pause and copy this code if you need to.
OK, so let's go back to our orfeu controller.
So if that's wrong, we're going to say utilities.
Utilities.
Utilities don't show alert, and what's the title?
I'm about the title in this case, of course, is an error.
The message is email or password to short.
That's a good enough error, and they're going to pass over the View controller itself, so I don't
know why it's not coming up with the code completion for us here.
But I was just doing what it's doing, I guess.
OK, so we can test that out.
We can go over to our iPod Touch.
And if we put in those values that are too short, then we should see that Arabic's pop up.
So I'm just going to put a little something there.
And perhaps they're going to get rid of the keyboard and then I'm going to hit it with Log-in, wasn't
it?
They go email a password too short.
Of course, register does nothing.
Oh, no.
We set it up in register.
So it does do something.
Login to short, OK.
And now if it goes longer
and we do it, we get nothing happening because we've just fallen through that filter.
Now, obviously, in a production app, you might want to give the user just a little bit of information.
So you'd split out this check and this check to let them know exactly what they were doing wrong.
So say to them, look, you need a longer password, you need a correctly formatted email, and so do
the email.
You do something called regular expressions, which are a nightmare, but it's something you have to
do.
And you can find regex on the Internet pretty easily for what you need, especially stuff like email
addresses.
So anyway, we're going to leave that one there.