So I'll come back.
This exercise uses a lot of the things that we have done in the past to help us produce an app that
can only accept certain type of characters.
So it's essentially going to be a text view that you can type the values that you want put only alphanumeric
values are accepted.
So let me show you the final product.
I've actually developed it in here so you can see I can go in here and say Hello my name he is in me
and I can write a lot of conversation as I'm writing.
It counts the number of characters and it doesn't let me go beyond 140 characters.
That's one thing about it.
The other thing about it is that I can't enter values such as curly brackets or brackets or whatnot
like I'm trying now see it doesn't I don't enter any of those.
Only us on human values are accepted.
So that's all I'm going to give you some time to do it on your own if you want you can pause the video
at this point.
And once you are ready or you decide that you know look at my solution you're welcome to or to work
along with me.
All right.
So let's go ahead to what.
I'm gonna start a new project I'm going to call this on Niigata cocktails.
And I don't have to put it there if someone else I'm not the first thing is designing a very very simple
user interface.
So there is a text through from that text you have somewhat of a lot here and make it a bit larger.
So the fun is going all the way to about say Tennessee there currently is nothing in it and maybe they
make the whole background that it is different.
So I can see things easier and I even lead a label to count up the numbers.
Right.
So I'm going to put it here.
And I'm going to place it there say there's audio on it says a maximum of 100 than 40.
So.
Thirty six maybe six.
At the moment I'm not going to really worry about where I place it exactly because we know that's going
to come up in our utterly adolescent.
So the next thing is assistant editor.
I'm going to go in here and say This is called My textfield.
This is called let's say a text counter.
So thanks counter.
Perfect.
So that's pretty much all I have to doing here.
I don't have to buy any more outlets for anything.
I do need to connect this takes view as a delegate and I can do it either here by controlling the writing
and saying delegate to view controller or we could do it in or view it lot I'm going to do it here.
So we know that our text view is delegating its tasks to a view controller.
OK so I'm going to go to the ones we're going to clean all of this up.
I don't want to have this much space up here.
I don't need to view that load at all.
I actually need two methods from the United States.
You would delegate.
So you.
I text you delegate and the two methods that I need.
One of them is called should change the text.
So this is the one that says that we should change the text that has been entered or not depending on
whether it is legal or not.
And then we have another one called text.
So did that change.
So let me quickly explain the difference between these two.
This one should change is the one we will use to determine whether values are legal.
So this is the one that we choose but the ones that you want are entered or not.
This is the one that says well they have been entered.
What do you want to do now.
I mean what do you want to do is you want to change these a little counter.
I want to make sure that our counter counts up.
Also if you notice this culture changes.
So if I have a lawyer text I'm on the card is more towards green and if I have less takes the space
the car becomes a wreck.
So at the very beginning is pitch green.
So on and so forth.
So this is the reason why we need to have these.
Obviously one of them is a bully return.
So they have to return something.
The other one doesn't have any return type.
So let's go ahead to the first one.
So you don't then write down what I'm going to do or get the packs of bright kids I can set join them
if not change.
It means they were OK.
Just like what you have done before.
So get the text from here.
Boy the characters said that you like which in this case is the alpha numeric and then joined them back
together.
If the result was exactly the same as what we had at the beginning.
It means nothing has changed and they are ok otherwise they're not OK.
There is also something else that you have to account for and that is backspace.
So I'm going to say I can't for backspace as well because backspace is neither an acceptably tight there
nor a member of alphanumeric characters.
So to do all of these things I'm going to go ahead and yet say I have a variable called Alfar or numeric
and that's going to be a jack.
There are sets of it.
It's called alphanumerics So I've got that.
Now here's something that you should know about the alphanumerics alphanumerics doesn't include L-Space
any so it has every value of the alphabet alphabet on all the numbers but does not include this space.
So that's something I have to do manually.
So I'm going to go ahead and say well if that's the case then say I'll find you that inserts and they
don't insert into it is a single space so spaces are ok then.
But I'm going to go ahead and say Let let's call it character set.
This is going to be fun you don't know worth it.
So this is how we want to break or our text entry.
So that's the reverse of whatever we have in here which is all the alphabet and the space the next thing
to do I'm going to say to let a call this one filter a text for instance or anything like that unless
they feel that the text is essentially all the text that we have in here.
Dot is it components.
Yes components separated right.
And we want to separate them by this Cocteau set.
And then you want to join them by nothing.
Why.
No spaces no nothing.
So let's see what we did in here.
If I can get everything in one line that would be great.
If not I'm actually going to do this.
I'm going to bring everybody down like that.
So I'm going to say filter text is what the variety of the text has been and to be about to determine
their validity.
Let's separate them.
Boy everyone here in this character said which is everyone who is not alphanumeric or a space.
So technically this character set is all of these values.
All of those all of those all of these values the Carol-Lee brackets everything square brackets all
of them.
So let's break the field test the text with all of these guys with separate pieces and then join them
back together.
Then if the third text was equivalent to the actual text then you could simply say return to of course
else return false.
That's about that.
So by now you have managed to return true or false depending on whether the values are valid or not.
Let me get rid of all of my comments.
I do remember that they have to account for the backspace so don't worry about that.
And I'm actually going to do that right away.
Let me let me reformat my text even though I don't like it.
But I think I have to because I want to make sure that you can see everything in one screen.
OK.
So that's my if else statement then right here.
Let me get down one up there as well.
I'm sorry this happens a lot with me because I'm trying to make sure that you see everything in one
screen and it's not confusing.
And I end up having an art form I know I don't personally like and I don't know if you guys like it
or not.
So in any case before we do this thing I'm going to say what if we want to check for backspacing here.
So I'm going to say if text was nothing had nothing has been entered.
But Ranjan lens was larger than zero.
So if something has changed that put nothing in the text has changed.
This only means hackerspace.
So I'm going to go in here for not.
This is what I'm writing here.
These can only be a parking space so it means that there is no text that has been entered.
But you have changed something on the set in that case do you return true anyway.
So let's see one more time.
What with it.
And I hate to do this but at least not one.
So we got our characters set the Insert the space to it we reverse it.
We made our filter text.
We said if it's backspace returned to run don't care about any of these guys if it is not.
And we ended up here if the filter text and the original text are the same return true.
Otherwise return false.
Let's see what we have until now.
So once it loads on my simulator
I should be able to.
Hello this is and I can not enter anything that I like.
It has to be alphanumeric values but obviously nothing is happening with this guy.
The little text counter.
So that's the part you have to fix in English text.
You did change.
So for this one I'm going to go ahead and say let's get the length of the text I'm going to say let's
just call this one our count or it's called current count you can cope with it or you lied.
Right.
So that's going to be my picks through our DOT DOT count.
So if we find out how many characters are entered so that seems simple enough.
Let's find our label which is called text counter.
So thick encounter dots text of course becomes a extreme value of discarding because you know this guy
is an integer.
He could actually explicitly say that it is an integer.
So now whatever it is that counts we put it in our text counters.
Let's see it up on the whether I'm teaching I don't want to run the app so many times because it takes
so much time but sometimes I feel like that is you know necessary.
HARLOW This is necessary.
Perfect.
Now to see if I could go on adding more text I mean jibberish or it.
It goes way beyond hundred forty.
We never accounted for that.
And obviously the color of it is not changing.
So we have to tackle those too.
One of them is fixing the color.
The other one is making sure that it doesn't go beyond 140.
So let's go ahead and say in here I'm going to go ahead and add a new color.
I'm going to say let me all of you back on when you B.G. background is going to be so kids I think the
new background color should be green at the beginning and the read at the end.
So it should be green while this number is close to zero.
And what I said By the time it has to become red.
So what should we do about that.
So this will they have to think of it I have to think of I need a variable let's call it anything you
know rate or ratio or anything like that that keeps increasing for read and keeps decreasing for green
at the same rate.
And you're right that in our My best approach.
And then you can see how it works.
I'm going to say let the ratio to be what ever we have currently as they count.
I'm going to say the current count divided by one hundred and forty because that's the maximum that
I want.
So if the court counts reaches one hundred forty then one hundred forty two point one hundred forty
becomes one.
But at the very beginning we will have zero divide by one hundred forty.
And that essentially becomes zero.
So to do this division against a I mean teacher I'm actually going to make this one a C G flat C G.
Lot of this.
You saw what the C-g flute of concocted count and divided by one hundred and forty.
And I have an error on the flute.
Yes.
So I have the flute of Kernstown by one hundred and forty.
And this number as you can imagine it goes between zero all the way to 1.
At some point.
So I can use this for my read but I have to kind of use the opposite of this for my green.
So let's go ahead and rename it.
I'm going to say this is red and then I'm going to say let Green be 1 minus.
Right.
Because at any point at the very very beginning VENDREDI 0 1 minus 0 becomes 1.
Towards the end of and red is gaining more more essentially more of the value of 1 minus one becomes
zero.
So I'm going to send you my graph is your eye color and I'm glad to hear that Carlist face that they
want to use.
I need something that can give me red green and blue with floating values one to zero.
So I welcome your display of peach tree the red Petri red green and so forth.
So that seems like the one I need.
So in this case I'm going to send out always one because it's fully opaque.
Blue is always zero because I don't want to have any blue.
Red is obviously red and green is obviously green and that's about that.
So we managed to have that and the next thing they have to do is I have to say this guy takes the counter
dot Micron's color becomes a new Biji.
So let's go ahead and test this out and let me get rid of all of these comments so it's easier to read
whatever is absolutely necessary.
So as I'm running the code now we will see if all goes then hopefully we will see that Hello.
So at the beginning is green and then as we move forward while it's becoming dark and towards or rather
it's really really really strange.
And we're getting to it now.
The only challenge you still have is that the characters still go beyond 140 and that's going to be
actually a very very very simple you know fix.
Here's what I'm going to do.
I'm going to go through here where takes the view should that change or not.
I'm going to say if text is equal to equivalent to the filter text then check something else and that
is text view dot text dot count is still below 140.
So before you decide that you should change this text or not decide whether the value of it is still
below 140.
So this one does not wants its mordent.
So here I can say all this is name and then I start typing a lot of random stuff as you can see the
colors is working properly as we go along.
240 It doesn't allow me to do anything anymore.
I can still use that space where they can type anything beyond that and that's about that.
So in this exercise I've managed to make a text that only accepts of two hundred forty office specific
set of characters and it counts the contest.
Besides about the new color for the bike you're on of the counter and applies to that label.
So keep it up to here on Bill and move on to.