So well come back again.
This lesson isn't an actual programming lesson is rather more of an administration work something that
we have to do to our code to make sure it is more readable both for us.
Or if someone else is going to work on the same project as us so and that is partitioning our code or
what we call arising or code.
Let me go ahead and to exclude then show you what they mean.
I already have something wrong.
One hundred forty five lines of code in my view controller class and that's really another good thing
because you have so much data and it's very difficult to find different things.
So for us to make sure that things are more readable for us in the future or somebody else we're going
to go ahead and partition the code into so many different files.
And we do that by using a very specific feature of swift current extensions.
Now here is how we use an extension.
I'm going to go ahead and add in your file that you can do it with file new file.
I'm going to add a new Swift file this swift file.
We call it whatever you want.
What is a very good practice and a very good tradition to call it by the name of the class you are trying
to extend and the function you're trying to add.
So for instance I'm going to go ahead and say This is called The View Controller plus timer function.
So I identified that it's called The View Controller Plus the function of time.
And when I create that and then when I get in here I need to do a few things I need to import.
I quit because that's the one I need for my my class or my extension then I'm going to say this is an
extension to view controller and that's all you have to do.
You now have a new extension that you can use for whatever that you know you have a part of the code
from view controller of.
So I could for instance go to View Controller say give me the timer function call it entirely pasted
in here and this will work as if it was in the body of the view controller itself.
So with that I'm going to go ahead and do the same thing for almost everyone in here.
I'm going to go ahead and say it make copies on the stuff so my life becomes a little bit easier.
So I'm going to copy that little part.
Say I have a view controller.
Plus you read the law.
So that's the function of the view that load.
So obviously we can add any kind of function.
So let me go ahead and do this one other time we're going to say give me this one view that lot put
it there.
So that's that then in my view control in the cloud that they had I have to randomize.
So let's go ahead and say command and noosphere file.
This is view controller across the randomise and in the months I'm going to rewrite everything to that
it's kind of a reminder for all of us extension to view controller within that I have the randomise
function.
So when I cut this by its entirety take it to the randomise.
So that's it.
And then I have a function called to make tiles let me copy some part of my code so my life is a little
bit easier.
Let me actually see what else I need so I do all of them in one go.
I need to reset action game mode action and it make tiles at least for now.
So I'm going to go ahead and say This is called the Wii U controller.
Plus I'm going to call people that say make titles.
So that's one file that I need then I need to reset and game more.
So I'm going to say Give me another one.
So the same name as before plus reset that one is it.
And then I'm going to get another one.
Say that same name plus game mode.
So now I have all of these Namik copies some more stuff but I have to copy that little bit on the top.
Everybody gets to be a kid.
You can sort of extension copy that to everyone and take a moment to reset and to make tiles.
And then I'm going to go out of your control take the reset I can put it in the Reset.
So if we haven't already done this now.
Now it's a lot cooler and easier for it.
There are many advantages to it is a lot cleaner is easier to hand this over to a colleague or someone
who works with you.
Also for me when I'm teaching it's a lot easier to show you things that are only in this one file and
they all fit within one screen.
So there's a lot of advantages of doing that and I really recommend you guys doing it so that you can
turn when I caught the game more action put it in the game mode.
Again this is the function we haven't done but if you'll be doing it hopefully sometime soon in the
next few lessons.
And let's go ahead and see what else we have we have the game.
Make tiles this function make toys.
Already it is quite long and I personally don't like very long functions and nobody in the programming
world makes it so.
Down down the end of the course when we talk about the advanced topics.
I'm actually going to change these when I break it into several pieces so it's easier to read essentially.
So now my view controller only has a declaration of variables and that is something you cannot put in
a separate extension.
They must be here in the body of the controller class.
But then I have the resets I have the game.
I have to make tiles which is a state a long record.
I have to randomize which is very nice and tidy and clean.
I have the timer function which is perfect and I have the view that law that calls a few things for
me and it still is quite tidy and clean and easy to read.
So that's all I wanted to do in this list.
And like I said no new programming just adding new stuff into a group of differing class extensions.
So they're going to help us categorize politician or more problematic term of modularize.
Our code is keep it up to here and we'll move on to our next lesson.