So I'll come back again in this exercise.
You are required to make a vague sharp sharp which is essentially something you have done in the past
that has a list of differing car design availability and what not.
But this time you're trying to use classes subclasses Nom's delegation's at any time and convenience
is on essentially everything we learnt in this past past section something that you know I should mention
is that you could choose to just watch me doing this this exercise simply because a lot of the things
I'm doing in this exercise are not necessarily needed for the purpose of making an app like this but
they want to go through them simply because I wanted to make sure that we have a review over them by
the end of it.
We should have something similar to this that you have a list of the cars that you can filter them through
available ones the ones that are out there was a car and we had to repair the cars that are seen on
cars or the cars or trucks and essentially you can think of this as an app that does either no managers
that I can't for for a for a rental shop that they have available because they have out cars they have
repaired cars and different types of cars.
And unfortunately because we haven't yet learned things such as a table view or your collection views
the display of them is a little bit ugly right now.
But everything else that we do is quite you know important and it's quite relevant.
So that's that's the plan if you want to pause the video for a few seconds.
You can get south on your own and try to make it on your own or if you can just start you know watching
my solution simply because like I said it's just it's just making sure that we have another review of
everything.
So let's get started in a few seconds
so I'm going to go to school.
I'm going to start thinking your swift project.
Mike.
Iowa's application called the shop hop
that a place you're not.
Let's get this thought.
And the first thing I want to do is I want to go ahead and add a new class when I say coquetries class
of that type.
It's called it color of that type and a subject and seems sweet sweet swift like would essentially remove
the subject not vehicle class has a few set of variables one of them is a name I call it name which
is a string.
And then it has a vowel color which is a U.
I call it.
And then I have let's say Max a year and that's going to be an integer.
And then when I have something that I call it a state for starters.
And that's essentially one of the three current ways out available liberal or three pairs and to do
that I'm actually going to make.
And you know so when I go in here and say let's have a swift file that is konked in arms and this enormous
call is to be a state.
It's going to have a case available.
Case out on a case repairs.
So that's my you know keep something in mind that this would end up changing this enough because it
needs to have a type.
It also needs to be chase I'd about table but I don't want to do that right now even though I enjoyed
it because that's the process of making up.
When you start working on a project you don't necessarily know what's coming up.
And it would be it would then be really useful of me to give you the solutions right away.
I want to wait for the time to come to face an issue.
Explain why that issue happened and why we have to change our enumerators so or anything essentially.
So let's go to I'll be here.
I'm going to say well now my Racheal has a variable called the status and the status is of the type
V here state.
So now I have another value in here.
Now let's go ahead and write in it.
So my head is going to have in the name of the type of string.
And if you have an input call of the type you like color input Max here which is of the type Integer
I would have been input this is not this which is of the type V.
And then of course if that name becomes input's name so that in itself that color becomes him color
self.
Mike skeer becomes impolite.
Skeer the self-taught status becomes input to the stocks.
So once I have my Veikko class I'm going to go ahead and start two other classes.
One of them is going to be called C down which is of the type B Kiang and it's going to be a subclass
of my vehicle class and I have another one which is same thing of the class superclass vehicle.
Nice cars.
So that's another one.
Perfect.
And each of these will have their own things down.
That's right.
For instance for the see down when I say it has a value cost current year which is integer I'm currently
now trying to think ahead.
I know that in a few stages from now I have to make my storyboard and I have to populated the information
and I'm thinking it would really help if I could put some dummy values in there.
So the moment we begin the phrase there is actually something there that we can see.
So to do that I'm going to go ahead and say I have a new class or a new suit file essentially.
And when I call this one dummys and my dummys has a class called class dummies.
I don't need a super class.
And inside it I have a few things one of them is my dummys array something I say a static Grauer are
dummies array which is going to be an array of vehicles and that's the thing that I need.
And very important thing is I'm going with a class function called populate array and that class function
is going to essentially populate this one.
Now the reason that I made this one Istar thing is that because I want it to be accessible by other
classes right out there need to essentially instantiate dummies was the same thing with the class function.
I don't want to instantiate the dummies.
I want to just use it every time that I need to.
So populating this array is just a lot of legwork and I'm going to try to do it as fast as I can so
we're going to spend a lot of time on this.
So I have this one and then I have the let's let's call it the V the one which is going to be let's
say a C done all of these values because I haven't yet programmed that it needs a specific to see that.
It doesn't auto complete it for me.
So here's a trick I could use I would say I'll use the in it from it and then change that to see that
because I know they're exactly of the same nature.
So I'm going to say my name is let's say who wrote the law.
I only see I can't think of the color is you.
I color dot it's red.
Now I don't have access to you by color.
So I have to import the you I checked and then I'm going to say maximum years or four out of four.
And the regular state is out for instance.
So that's one less capitis a few times.
And this is going to be very cold too.
When I say this is a fourth This is five.
This is blue.
This is available.
I'm going to duplicate it again and this time and say it's going to be a fiat.
If there is such a thing you know maybe five again and this time it is available and it's going to be
free.
One more time I think dove would do for us.
And this time I actually am going to say it's not a see that and this thing is actually a truck.
So this will be a truck of a dodge and it will be say on the trail of a car for a truck with a stick
and it's a trailer.
So I've got four vehicles and all four of them they have to go to these dummies.
Of course this is something that you know you only do it when you are doing your testing and stuff.
Otherwise it doesn't really happen that you have to manually add of this stuff to your arrays or members
to your arrays because you wait for them to be dynamically either from either a backend or way different
users from different parts of the network.
But since you don't have that right now we have to essentially do it manually.
So now I have some dummies that they can be populated.
If somebody calls dummies that populate every now let's jump into our view control and started using
those.
The first thing I'm going to do is go to my view controller and say dummies that populate it.
So I know by now this while you dummies that are dummies array has already gotten the values in it which
I'm not going to use it like this.
You have to use it to populate our text you know.
To do that let's go to a story.
And you know finish this fourth of my storyboard is going to have a fixed view which is the larger piece
in here.
I'm going to not like that.
And I say let's place at the bar that I'm when I have a segmented control on the top.
Are about here and the other one and the other and this one is going to be between sit down and talk
boxes and sit downs and none of them is neither of them is going to be selected or at the beginning.
This one however is going to have three members.
Those three members are going to be available.
A The second one is and is not currently selected and the next one is going to be out.
And the third one is going to be repairers.
So exactly the same names as we have in our you know.
So we got that part taken care of.
Now the next thing or essentially the last thing in here is I'm going to have to connect them to some
sort of outlet in my view controller.
I'm going to go to Assistant Editor in here.
I'm going to say this one is going to be a status action because that's where you decide what kind do
you want to show.
But they're available out or repairs.
And then this one is going to be that type action.
So that's the type of action because it tells us the type of the car.
And this one last one here is my text to you or raise text.
I know they also have a button down there which I should have made it.
That takes us to I think you get someone to do that right away as well.
So that one in here essentially says you or I know this one has a different background.
And this one is has an action saying add in you go to the new code to you.
And that's about that I don't like.
So now we got all of our actions on all of our outlets in our view control over all of this I'm trying
to split them up simply because I know you know how to do them.
So the first thing I want to do is this I want to make sure that one of them actually does something
very simple like listing all of the values in the dummies that are.
So let's do that first to do either of those you have to find out which.
But then undi is segmented control.
We have clicked on.
So I'm going to go in here and say I have a let's call it index which is my Sandesh as you or I segmented
control because I know it is a segmented control dot the selected segment index.
So I find the index that they have clicked on and I need the exact same thing for my type action.
Because here I have the type of segmented control.
So I'm going here and say in the state of status let's switch that you switch the index in case it is
zero.
It means available simply because that is available Varney's out to is repairs.
So that's that will do something about it in case it is a one that means out and we will do something
about it.
And in case it is true that means repairs and we will do something about it in the default mode just
a break for me to be able to you know simplify my life and I actually copy this bit and pasted in here
as well in the type of action because I have cases zero on one.
So zero would be for sitdowns and one would be four tracks and not just go ahead and see what you want
to do and what you want to do is this.
If the first the first by the end of the segment that control if you want to go ahead and get the array
from the dummies which is called the dummys array and you want to filter that out so only the ones that
are available are shown if you press 1.
Only the ones that are out on the press pass only the ones that are repete.
So if you want to do that you have to put them inside an array themselves.
So here's what I'm going to do say I have a very up here let's call it the viable current array which
is an array of vehicles.
Right the code to press this status.
I'm going to go ahead and say My current array becomes a brand new one essentially I initialize it.
So that part is taking care of.
And then when I'm switching the index for the available ones I'm going to say for any color in dummys
array.
Effect way cool or any Ricca DOD status is a very status that is available if that is the case.
Then add them to my current array then current array dot append.
What would I want to add and any week.
So that's about that by now we managed to have all of four elements in our dummys array filtered into
the ones that are available and they're all in the current array.
Same thing happens for a case 1 and same thing happens for K-Stew only going to copy everything.
I'm going to sit in here say for anyone in there if they are out then add it to the current array for
the last one.
If they are other repairs add them to the current theory.
So by the end of this switch which every case we have chosen our current array is now properly populated
with the correct objects in it.
So we have to do a very similar thing for when we tap the type action as well in here.
We should check the Vache status.
We have to check what kind of vehicle it is.
So I'm actually going to copy everything in here.
Say right at the beginning when we press the type action again do the same thing say initialize current
array as a new era just like what we did here and then say the same thing exactly.
So I'm copying Sir's a bit faster for any vehicle in there if the if statement is a little bit different.
If this.
Is it see sedan see Don is any We as see done.
So if any cable is a down if that's the case then the array append does see that.
So like that we managed to know for anyone in the dummys array if their vehicle is of the type sedan
then added to the current array.
I'm going to copy that in my father's case and the only thing that is going to be different is if it
is as truck of course the naming.
You could change it as this truck.
So now I have these two functions that they each do something for us in terms of filtering my content.
Now my code is becoming quite crowded and I also don't like you know the formatting that is in here.
So what I'm going to do is I'm going to put either either of these two in a separate extension so when
I go in here and say command and swift file and this is going to be my view controller plus type of
action.
And in this font is very simple.
All I'm going to do is I'm going to say extension view controller and by extension view controller I'm
going to go ahead and cut this whole plot say this entire part goes to type action.
Perfect.
And now I can formatted the way I like it which is very important for me.
So like dogs I like him to be this way that's easier for me to read.
And don't worry about that one error that you're seeing up there the error is simply saying I don't
know what's a segment that control because in the extension I have to import the.
You like it.
But other than that everything is working the way we wanted it.
So that is all type action.
I'm going to go ahead and carp it is again say swift find this.
I'm going to call it the status action so in my satisfaction once again I'm going to do the same thing.
I know I have to import the kids and I know it is an extension of you controller.
And then from my view controller I'm going to go ahead and say stop the section let's cut it and put
it there and then that's about that.
I can reformat it the way I want.
You could do whichever you are used to.
Or if you're just washing it just bear with me that you know because here's how I like it to be.
So now when we press those buttons we have managed to successfully essentially filter our array to the
ones that we want and place them in the current array.
What we haven't done is some sort of a Mackell ism that goes ahead and shows it in our arrays text do
you.
I'm actually going to go put my rest takes you up there simply because it makes more sense.
And now we have to write a new function that shows whatever you have in the current array.
In the Rose text you call that function fine show a string.
I'm going to have a title input title which is a string and how an input array which is going to be
array of vehicles.
So that's about that.
And the body of the function.
I already have it from the previous one that they did.
So I'm actually only going to copy paste that so I don't have to waste your time going through it.
It's a very simple you know text production.
It says there is a value of a string that you want to show.
It begins with whatever title that you have with that title.
We are carrying to it.
And then for any vehicle in the trade that we have we go through the next line with TARP and then we
put the name of the current uppercase or a line down and we go to tabs and then we show the color of
it and then be sure the Year of Faith and then we should start to solve it.
Now a few things I have to change.
I'm one of them is actually very important.
The most important one is this one.
How are we going to show the color of something because as you can imagine it colors such as this one
your eye color that red.
It's not text.
It can't be red eyes or E as a string.
So we have actually to write something that takes colors and converts them to names.
So unfortunately there is no such a mechanism built into swift or excoriation I have to make my own
version of it.
So I'm going to go ahead and start a new file called swift and I'm going to call you white collar last
name.
So this is a new extension for you.
Kardash so in yeah I'm going to say an extension for you.
I call parlor and I think they have to import you UI kit.
OK so now I'm here I'm going to go ahead and say let's do this say variable name that is this string
and that this thing I'm going to say switch to self.
And then I'm switching self I'm going to say in case it was your eye color dots.
Then read the text.
So for every color I'm going to go ahead and write a value which is a text value that we can return.
So I'm going to copy this a few times.
I'm not going to do every case simply because you know we don't have much time.
But for red blue green yellow sign on either end or the dark gray and light gray maybe for all of these
will take care of it.
So four lights created right Gary for the directory and directory for sound and so on.
So on and so forth.
So I make sure that for every value that I have I get some text value as a result.
So red.
And in case of default our return which obviously doesn't really happen.
So what this extension does for us is that it offers us a way to know whatever the color is.
What is the fixed value of it.
Now I could actually use this.
I could go to my of your controller and then I could say each week a color and then get the name of
it.
So I think that error will go over.
Yes it did cause it.
So now we have a string that gets shown in here.
And let's put this in a separate extension as well.
I'm going to cut that.
Say this is the view controller Plus show a string and this one would be in for you.
It would be an extension to you control.
And I have have this one function.
And now we can actually go ahead and use this one.
When are we going to use it.
We're going to the end of the year start this action saying once you did this switch and we were happy
with its results say switch a string.
And yet for the input array I'm going to say current array.
And for the title the title depends on the one of these cases.
So you could either introduce a string that each time gets one of these values or you could have run
this function inside the body of all of these cases.
So either order is going to be essentially the same so I'm going to go ahead and actually opt for the
second solution.
I'm going to say in case of zero.
Go ahead and say IMPA title available.
And those are array in case of one.
Go ahead and say in the title is out and the aere in case of repairs going here say repairs and that
that.
And you have to do the exact same thing for our type auction type auction I'm going to go in here and
say well when you're doing the you find the see dollars go ahead and say idea and title is sitdowns
on at the end of here implied is trucks
OK long you've tried so far.
So let's run the application at least one see if you haven't done anything terribly wrong.
And if you have done so much coding without anything happening and you have to see how you're doing
and if I press available we see the available cards out out cause repairs around there is no one sit
downs.
Are these three trucks of those.
So maybe it helps if you put one of them at repair.
So I'm going to go to donees.
I'm the dummy and when I say this fun is the repairs.
Now of course we haven't really planned for anything that says from the available vans.
Show me the sedans.
Right now each of these two segmented controls they work essentially independently and I leave that
to you guys to figure out how you want to do that.
But you know in a real functioning application especially with the design that I have that on the top
you have the available ones on the top you have the status ones.
And then we have the type ones you want to make sure that these two correlate to each other.
So pressing out on anthrax should show the trucks that are currently out but I leave that to you guys.
For me however let's go ahead in here and say we have everything up until now.
The thing that we don't have is going to be adding a new one and then from there on adding one more
thing in here.
So let's go ahead into my story about and in here I'm going to go ahead and add a new controller.
So this is my new controller.
So once again in here I'm actually going to cheat and I'm not going to remake everything simply because
I don't want to make this video very long so I copied and pasted from my previous article they had done.
And these are all the things that we need in here.
We need a little of button up there I need a type I segmented control.
Then we need a text field in a color or a slider or we need a color indicator.
We have a two step or one step at essentially plus minus.
And we have a status that you know at the end if you can choose what is the status of that card.
I'm adding to the network or to mine to my data essentially.
And then I want to go ahead and say let's have a Segway.
And that's like it is from here to there.
Let's call it 2 here to say.
I am going to copy that name to my view controller and say in the code to add new self performs segue
with identifier that one with no senders right now.
And live it on the application once again.
We should be able to navigate successfully into our new controller even though there's really nothing
happening in there.
So if we can go in here and now we have to worry about what we should do in this new controller.
So for this next thing I'm going to build the pieces for my ADD the view controller which is in here
for this one I'm actually going to pause the video and do it because it's such a repetitious thing and
I don't want to waste your time.
So bear with me for a second.
So when the video was on pause I did the following things.
I added a new class called add the View Controller and that's obviously a subclass of view controller.
I applied that to my view controller outlet in my storyboard and I connect that these different outlets.
They're a text field a label for the girls a label for the warning a slider for the color and a box
that shows the colors.
And these are here so this is my textfield This is my warning label that has that little box that I
can see the different colors on it.
Maybe I make it.
I don't know a different color by default.
This is my little label.
I see the different years.
And that's obviously my ADD.
And these two are now connected to two functions via the value changed event which one of them is change
of type.
The other one is change of status.
Of course I have the action that are in here.
I have a value changed color change that is the one that applies to the slider.
I have a step her value change that is for when I changed gears I've ever made a mistake in here I'm
going to fix that is not a touch up inside change color of a number of years is actually value changed.
So those are the things I have in my ad the view controller.
Let's go ahead and get started with them.
So the first thing I want to be able to do is I want to be able to change the color by the slider so
to do that I need an array of all the colors that are available to me.
And then to go ahead and say I have something called the valuable collar's array.
And that's going to be an array of you.
I color and I'm going to have to populate that somebody somewhere right.
A function populates collar's array.
And that would do that.
It really helps me for the reasons that you will see really soon enough Does this area in here and these
callers are in the same order.
So I'm going to copy these.
When I say copy I'm going to go in there and say Claras array becomes an array of all of these guys.
Of course not the way they are I have to get rid of all the cases and I'm going to do that and I have
to get rid of all of these.
So you might call a blind curate all the way to light gray.
So I paused the video and I populated my colors array the next thing I'm going to do is I'm going to
say my color a slider so color the slider that minimum value becomes a zero color a slider the maximum
value becomes my collieries array doth count minus 1.
So essentially becomes where there is the maximum number there minus 1 which is the range.
We can go through as if you are using the array.
So doubts about that was giving me an error saying that this value is an integer word here.
You need to have a flow with someone to say Give me a lot of that value get integer converted into a
float.
So now if I go through a wide Slider I should be able to see different colors.
Let's go ahead and implement that.
So to do that I have to essentially say color box dark background color becomes colors array and someone
from crullers array should be there.
That one depends on where my slider is.
So let's go ahead and say let's index becomes.
I have to get the value of my a slider.
I'm going to say my curve is neither to value but as we know this is a float value.
So if I can convert it to an integer and even if I said this is an integer that value might actually
reach the upper bound and because of that I'm actually going to have to manually convert it into an
integer.
And as we saw it sometimes earlier I have to around it to know that the value that I'm getting is exactly
the correct value.
So when I'm rounding I get any value between 0 2.5 to become 0.
Anything above point 5 to become one.
So on and so forth I get all the boundaries that I need and I'm going to say colored box by gun color
becomes color as array index.
This index Let's see if that part is working.
We're on the application
and if I go here and I say that I had crushes.
The reason it crashed is something I completely forgot and that is we never actually use this array
or this function.
So I'm going to go to my view of the Lord and say here populate the array as well so the array is not
empty.
So I'm going to run this again and this time and it loads up we shouldn't have that issue anymore.
So now I can go through all the columns that I have in my array.
Perfect.
So that part is taken care of.
Now let's go ahead and on the ISTEP her value for here for the changing of the number of the gifts that
should be really easy here in here and I'm going to say give me the years label dot text and that becomes.
And here's the value that they want to put in the string of the text.
I want to have a interpretation of that.
And it's going to be a bit of a long one but it's going to be send there as you point a step or not.
That's one I'm going to make it.
Give me the value.
Now the value is a double.
So I'm going to say give me the integer of that value.
So it's a very long process.
But it says give me the integer part of the send as is the per value interpreted.
All of that into a string.
So let's right now
and here I can change the values.
So the next two things are changing the starters and also changing the type and both of these they kind
of need to be stored somewhere simply because as we change these guys we are not going to do anything
with them unless you press the add the button.
So we have to store these two values somewhere that we know our user has chosen to be a sideline or
an available one.
And then when we had the odds but then they get to reflect somewhere.
So because of that I'm going to go up here and say Give me your valuables.
One of them is going to be valuable and select that type.
And that's going to be a string.
And the other one is going to be valuable new movie called dictionary.
And that's going to be a dictionary of a string.
And in.
And they're both optional but explicitly aren't optional.
So here's what I'm going to do in my change of status in my change of status.
I'm going to say let's find what is this not as we chose.
Going to say let our select that index to be let's get send there as your eyes segmented control and
then let's get the selected segment index.
So from this selected segment index which is this one from this status we're going to get zero for available
one for out and two for repairs.
So we don't got Why add the view controller and say based on data based on whatever is the status they
have selected.
Now here is the part that we have to go back to our income and make some changes because I could run
if a statement say if selected index was zero set it today.
If it was run say to the other one.
But if we choose to use the roll values things are going to be a lot easier.
So to do that I'm going to put my arms I'm going say my available is zero and my out is 1 and these
other are all values.
And then the moment they do this is going to give me an error saying so you have to type your income
and I'm going to say fine my arm is in.
And while I did I'm going to make it.
Chase i3 traceable as well.
So I don't have to come back to it anymore.
So now my arms they have names my cases they have names and they also have a role value.
So now I could simply go back to mine.
And if you can for one year I could say instead of running an if statement I could say we used the roll
values to find out what we want to put in there.
So I'm going to say no we can't.
Dictionary.
And I'm going to call this one the status keep the status G.
That's going to be and value that they want to put it is this regular state.
I'm going to get the roll value wrong value under all that you want to get it from this guy.
Select that index.
Now it's a little bit of fun.
You know a challenge in here.
One of them is that I'm entering a vague killer state twist throwing into my new Quaker dictionary my
fecal dictionary does I accept any which makes it perfectly fine to enter values such as this one but
the compiler cannot compile a value such as this number they have to do is I have to make sure that
I interpret this as a string.
So I'm going to say this is actually a string.
I'm trying to produce.
So get this converted into a string and place it in my status key.
And now you're saying.
Are you sure this value which is an optional one does exist.
Then I'm going to say yes I know it's absolutely there.
I just realized something and if you were super perceptive you probably saw it before I did and that
is my new vehicle dictionary was never initialized.
I did define its type or declare and.
But they never initialized it so I can actually go ahead and say let's initialize it on the fly right
at the very beginning.
New medical dictionary is an initialized dictionary of a string.
An array doesn't currently have any id..
It's just an initialized but soon we're going to you know enter values into it.
So so far I got to store my status somewhere in here.
The next thing I want to do is I want to store my type or at least remember its number.
So for that again I'm going to do this because again I have an.
Selection index from a segmented control and then I'm going to say switch this value switch selector
index and if case zero say select that type is going to be done simply because I know that zero is down.
One is Iraq.
I'm going to go ahead and say in case it was one selected time make Maajid truck.
So I am storing that value.
The change of the type in something called select that type as well I think case it was the just bricks
don't do anything.
So almost everything is ready except that they have missed out on a few things yet one of them is.
So the record that the change of status in our in our dictionary we have recorded record number of years
we haven't recorded the color we haven't recorded.
Whatever is the value that we get in the text.
So as you can imagine when we want to head out the we need to know the status we need to know the number
of years color and the value of the text.
And we need to know which one it is of these five is still three of them we haven't decoded anyway.
So I'm going to go in here and say some of them are easier than the other ones so let's do the easy
ones first the easiest right now is the number of the years.
So then we change it.
This is the value that we are storing.
And I'm also going to say new way kill our dictionary and the value for let's call it here is she is
going to be undervalues or they want to enter into it is whatever we find in there.
So which is essentially the sky.
So integer of that so that value I place it inside my Gere's key.
So the moment the value changes on the number of the years that value we see it in there.
And if you want we can actually use the use the combination of these two to show it on your years label
as verb which is a better practice generally.
So now there is a stored somewhere.
I'm going to copy that.
Say that is what I want you to show.
So I don't do the same thing twice.
I placed the value inside my dictionary then I get the value from the dictionary and wrap it and place
it inside my label.
So by now our dictionary has the year's key it has this Thatha ASCII.
So these two are taken care off with essentially for these two four fold.
Now the missing pieces are one of them is the color.
The other one is the value of the text.
Let's fix the text field first because it's an easier one.
I'm going to go in here and say my textfield whatever I call it which I don't really remember.
Next name takes VIDOT delegates to self.
And I'm going to go ahead and say your view opens for you.
All right.
Textfield delegate it conforms to the textfield delegate.
And since it does that I can use a function such as text fields should return.
And if it does do that.
Here's what I want to do.
I want to say the new Charles dictionary value for the name.
I want it to become text field dot text so whatever is in there put it inside the name key.
And of course they text in Dot resign the first responder.
So every time we had to enter on the text field we get rid of the keyboard and we all sort of what you
call the a store the value of it.
But there is an error because they forgot that this is a boolean function.
I have to say return TRUE was at the end of it.
So that part we took care of.
The most difficult one perhaps is this one the changing of the color which gives us a color not trying
to fix not what we need to do is we need to find that color and put Hughson name out of it.
And that is something we have already done in your eye color name.
So I can simply going here and say every time you do this you go ahead and say No raker dictionary value
for color she becomes and the value needs to have is exactly the sky which is a color dot name.
So I'm going to say get the name of that color and place it in here.
So by now we have managed to get the color put in a dictionary get the name it in the dictionary which
is in our text field here and get the gear within our dictionary.
Get this that this is in our dictionary and find the type and put it in here.
So finally we have to actually add all of those things.
And before that we actually run a little test.
So I'm going to say let's have another function call validate and what validate does is make sure that
everything we want is already selected.
If somebody is still there is going to tell us hey you have to do something.
So that is very simple.
We have to make sure that our dictionary has four members.
So I'm going to write.
If your vehicle dictionary dot all values dot values dot count is below 4.
If it is not 4 yet and or month or select that type is near.
It means we either haven't selected everything that we need or we haven't selected the type that we
need.
If either of these things happened do this say warning label that hidden becomes false.
So we can actually see it now and the warning label dot text because all fields are mandatory.
So that's about that.
If that didn't happen then you can do something.
Let's go ahead and really quickly use that before we actually use it.
I'm going to say whenever I had the I'd rather do this say validate.
All right let's make sure the validate returns a boolean.
So if this was the case.
Dude all of these things and return a false Indianness return true.
Return through I'm going to do something else in there and else I'm going to say warning label hides
again.
So this thing I enjoy I've actually done something quickly.
So in my action let's say if validate and the valley that if it is true let's say I get on this mess
and I was a on.
So I'm going to commence this temporal way.
So here what we have is this we go and we try to validate whether our user has entered everything correctly.
If they haven't we see a little warning if they have we get rid of the warning and we push to push back
to our previous viewpoint.
Let's go ahead and run this application so we're almost at the end of this development.
So if I go to odds a new one say sit down and head out.
It says All fields are mandatory.
If I say the name is for I I that is still the same thing is going to happen put in place like all five
of them had are that's going to disappear.
It means everything has worked well.
So now the final challenge is we know we now have a proper dictionary that has all the information I
have has for green one and out and we have to send that dictionary to our type whether it is Saddam
or the other one and make in you we can.
So let's see how are we going to do that.
So to do that we need to make sure that both are sit down and traunch they can actually initialize themselves
using a dictionary.
So in it using a dictionary to do that I'm going to say I have a convenience.
It's not like that convenience in it.
And that convenience in it has an input dictionary of the type dictionary of a string.
And any.
All right just like what you have done when they're studying convenience and it's I mean you know when
I say God let go and let is going to be are all of the values that we have in there so we have a name
which is going to be input dictionary value for our name shame.
So we got that one of course we have to get that one as a string.
So that's one of them let me copy that a few times even a little bit different but I'm going to copy
them nonetheless.
And at the end we have the else part for the guard.
So the next thing is years.
So I'm going to say here this is going to be years g and that is going to be an integer because I know
that when we were producing it you know at the view controller I said here's Key is going to be an integer.
So back into our Siddhant I'm going to say so we got here or there.
Right.
And when I say I got the name as a string I got the years as an integer.
The next thing I need is I need to get the colorists string.
So it's going to be color.
I'm going to call this one color a string and you will see soon why I'm putting a different name for
it so color key as a string and I need to get my status.
So I'm going to say is that this again a string.
And that's going to be a status cheat.
Let me double check all of these names start the skin color Caig years skie name.
So you know the view controller is that the Schaik your skin color key and Name Key perfect.
So everything is exactly as it should be.
And now I'm going to say if all of this went well what they wanted to do which is no surprise.
I want to sell.
It's not that I want to end it with the other in the original in it are the designated in it as we call
it otherwise I want to return that yes.
So that part is taking care of.
Now the problem the challenge we have is a few things name is there.
That's perfectly fine.
Yours is there.
That's also perfectly fine.
Aponte I spelt it wrong.
I called it Max years not Max years but you know you know what that is.
These two however are rather simple simply because the value that they have for the state is a string
and I can't use a string for what they need.
I actually need to get it as a Vache real estate you know.
So I'm really going say OK here's what you're going to do.
You got to say valuable.
Stop this.
I'm going to put it away.
The font to be available.
Then you're going to say for any case in the killer state not all the case says he does what you want
to do.
You want to say if the status is or was there value that you have in any case as a string.
So I'm going to say interpretated as a string.
If that was the case then here's what you want to do.
You want to change your status to become a death case any case.
I think I should have used the were all cases yes.
So using this.
What they didn't.
I managed to convert to whatever we found in here as this thing went through all the cases and I found
it as not strange rather a case from this on.
So now we can use this stock this year.
And finally to probably the most difficult one and that is how are we going to get a colorists throwing
which is a string and convert it to an actual You eye color because he in here is expecting us to give
it the color the color of once a color.
So we have to do the opposite of what we did here in the past.
He said you like color plus name.
Now we have to say is string plus color.
So we have to get the opposite effect.
So I want to go start a news fine.
I'm going to call it a string class.
Color or color or whatever you want to call it.
And in here I'm going to have to import you I hit him for you.
I get I'm going to say that's an extension or a string.
So it adds something to a string.
What it does it says color of the type you eye color is going to be switch self.
So it shot through its sewage south and here's what I want to see in the switch.
I want to see that for Chase.
Let's say black you have to return what should they return.
I have to return you I color dot black and white is the complete list stuff.
This is these guys.
Everyone in here should be returned.
Similarly someone going here and say hey it's paste all of that and I'm going to pause the video to
clean these.
So bear with me for a second.
So what I have is in mutant or in your variable from any string that may return a color.
And in case that the string is black is going to return your white color after lie in in case that string
you sign on is going to bring you eye color.
That.
So let's go back to my site and see done.
And yeah I'm going to say get the eye color from color tiara and then from the colors the are yet dot
color and I'm going to force on drop it because I know that thing exists.
So with that in mind now that we have all chameleons in it but we added things just a tiny bit so we
can see them a little bit easier.
Everything in one screen now that we can fit into a dictionary.
I'm yet to back a C Don.
I'm going to go back to my idea view controller and in here I'm going to go ahead and say let's do a
few things.
I'm going to say if they didn't work just return don't do anything I don't else as such.
Then I'm going to say valuable new we can.
It is going to be of that type.
And then I'm going to say if selected type is sit down here's what they want to happen.
I want the new color to be seen on all
of the input dictionary and that is going to be new vehicle dictionary if I do that and I successfully
produce a new vehicle.
Here's what they want to do.
I want to say dummies not dummies array dot a.
And what would you want to happen.
I want to append the new vehicle.
So this way every time we pressed the odd action we test if it is valid.
We do this we make a new we can of course you can imagine the other side the IT WOULD BE else or else
if you want it selected type is tried are you have to do something else in here.
I'm not doing that simply because I haven't written the code for that's right and I'm not going to do
it because it's going to be very very similar to what we have in here.
So in here I'm going to say let's dismiss the and if it was unsuccessful just go ahead and test our
application.
If it all works we should be able to add the carrots through our art and then read them back at our
main view.
So right now we have available for and dodge and out Crolla repairs Fiat and sedans Crolla forward and
it's not like going here and they have a sedan by the name of people and the color is say sign on.
And then I've got Mike Schiro one is quietly available and I'm going to add it.
One is that you automatically are transitioning back to our main view controller.
I can go to available is here now.
So we either had one successfully in here.
So that's pretty much the end of this very long lesson.
So we began by having an interface that has our view as one of them shows a number of objects in an
array.
The other one can produce a new one.
We try to split our code into as many extensions on as we could.
Right now our application isn't all that extensive but even now it's over a hundred lines and you can
see going through all of these might be a little bit tedious.
You have to break all of these into separate extensions or if you're working in Objective-C separate
categories.
So every part is going to work you know independently.
I'm going to actually pause the video and do that in a second now and then show you how it would be
if it was a real life practice.
So what I have done while the video was on pause I have actually broken my ad the view controller in
as many extensions as I could.
One of them is the main view controller which has all the declarations and it has the view that lot
and I have the populates color into a new extension.
I have the text fields delegation are changing the color changing the gears changing the start changing
the type.
Validate an odd action.
Now this really helps you or any other developer who wants to read your code later on so that they can
easily go to I don't know the part that changes Stathis read only a few lines of code and they understand
what's going on.
So with that in mind let's close this lesson it became a very very long one.
I apologize for that.
And like I say it wasn't meant for you to follow along it was just more of a demonstration of how you
should think about your development.
There is of course a million things still you can add to this application and I actually encourage you
to do it.
Go ahead and get the you know the convenience in it from sit down and added to the to the truck you
know class and change stuff in here.
Troy to our customer tributes to either of the classes so you understand how each of them work of work
here on your income to have more values in there and you can actually expand on this application once
you learn other tools such as your table views or collection views.
You can start adding images for each of them you can have some built in images within the bundle of
your application on the main view of your app.
You can have a little photo for it that you can see each of them with a little picture.
There are a million things you can do and I really suggest that you guys work on them and try to to
you know expand on that as you can see everything that we did in this happy cation.
Our thing is that we already study it but it's not necessarily used the way that we do it in the in
the lessons because when you want to practice them things become a little different.
Perhaps at the beginning of the development none of us thought that we need to find a way to change
the outcome where the names of the colors into a Strange's or the opposite.
You have to convert the names of the streams into actual callers.
So these things you only learn them by practice so that I will see you in our next.