1 00:00:00,270 --> 00:00:01,430 So well come back again. 2 00:00:01,440 --> 00:00:07,140 This lesson isn't an actual programming lesson is rather more of an administration work something that 3 00:00:07,150 --> 00:00:11,550 we have to do to our code to make sure it is more readable both for us. 4 00:00:11,590 --> 00:00:17,370 Or if someone else is going to work on the same project as us so and that is partitioning our code or 5 00:00:17,370 --> 00:00:20,090 what we call arising or code. 6 00:00:20,090 --> 00:00:22,940 Let me go ahead and to exclude then show you what they mean. 7 00:00:22,980 --> 00:00:24,390 I already have something wrong. 8 00:00:24,390 --> 00:00:29,820 One hundred forty five lines of code in my view controller class and that's really another good thing 9 00:00:29,820 --> 00:00:34,290 because you have so much data and it's very difficult to find different things. 10 00:00:34,290 --> 00:00:39,510 So for us to make sure that things are more readable for us in the future or somebody else we're going 11 00:00:39,510 --> 00:00:43,360 to go ahead and partition the code into so many different files. 12 00:00:43,500 --> 00:00:48,660 And we do that by using a very specific feature of swift current extensions. 13 00:00:48,660 --> 00:00:51,300 Now here is how we use an extension. 14 00:00:51,420 --> 00:00:55,410 I'm going to go ahead and add in your file that you can do it with file new file. 15 00:00:55,410 --> 00:00:58,530 I'm going to add a new Swift file this swift file. 16 00:00:58,530 --> 00:01:00,410 We call it whatever you want. 17 00:01:00,440 --> 00:01:06,450 What is a very good practice and a very good tradition to call it by the name of the class you are trying 18 00:01:06,450 --> 00:01:10,020 to extend and the function you're trying to add. 19 00:01:10,020 --> 00:01:16,690 So for instance I'm going to go ahead and say This is called The View Controller plus timer function. 20 00:01:16,830 --> 00:01:22,220 So I identified that it's called The View Controller Plus the function of time. 21 00:01:22,290 --> 00:01:27,760 And when I create that and then when I get in here I need to do a few things I need to import. 22 00:01:27,900 --> 00:01:34,050 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 23 00:01:34,050 --> 00:01:38,580 extension to view controller and that's all you have to do. 24 00:01:38,580 --> 00:01:44,250 You now have a new extension that you can use for whatever that you know you have a part of the code 25 00:01:44,250 --> 00:01:45,730 from view controller of. 26 00:01:45,840 --> 00:01:52,200 So I could for instance go to View Controller say give me the timer function call it entirely pasted 27 00:01:52,200 --> 00:01:57,700 in here and this will work as if it was in the body of the view controller itself. 28 00:01:57,900 --> 00:02:03,420 So with that I'm going to go ahead and do the same thing for almost everyone in here. 29 00:02:03,510 --> 00:02:08,460 I'm going to go ahead and say it make copies on the stuff so my life becomes a little bit easier. 30 00:02:08,610 --> 00:02:10,260 So I'm going to copy that little part. 31 00:02:10,320 --> 00:02:14,450 Say I have a view controller. 32 00:02:14,570 --> 00:02:17,120 Plus you read the law. 33 00:02:17,340 --> 00:02:19,540 So that's the function of the view that load. 34 00:02:19,650 --> 00:02:22,500 So obviously we can add any kind of function. 35 00:02:22,740 --> 00:02:29,400 So let me go ahead and do this one other time we're going to say give me this one view that lot put 36 00:02:29,400 --> 00:02:30,320 it there. 37 00:02:31,390 --> 00:02:37,740 So that's that then in my view control in the cloud that they had I have to randomize. 38 00:02:37,770 --> 00:02:41,980 So let's go ahead and say command and noosphere file. 39 00:02:42,010 --> 00:02:50,730 This is view controller across the randomise and in the months I'm going to rewrite everything to that 40 00:02:50,740 --> 00:02:57,910 it's kind of a reminder for all of us extension to view controller within that I have the randomise 41 00:02:57,910 --> 00:02:58,940 function. 42 00:02:59,040 --> 00:03:02,870 So when I cut this by its entirety take it to the randomise. 43 00:03:02,980 --> 00:03:04,440 So that's it. 44 00:03:04,900 --> 00:03:11,140 And then I have a function called to make tiles let me copy some part of my code so my life is a little 45 00:03:11,140 --> 00:03:12,650 bit easier. 46 00:03:12,800 --> 00:03:15,720 Let me actually see what else I need so I do all of them in one go. 47 00:03:15,730 --> 00:03:21,740 I need to reset action game mode action and it make tiles at least for now. 48 00:03:21,880 --> 00:03:27,160 So I'm going to go ahead and say This is called the Wii U controller. 49 00:03:27,160 --> 00:03:32,610 Plus I'm going to call people that say make titles. 50 00:03:32,620 --> 00:03:38,370 So that's one file that I need then I need to reset and game more. 51 00:03:38,410 --> 00:03:40,510 So I'm going to say Give me another one. 52 00:03:40,560 --> 00:03:46,870 So the same name as before plus reset that one is it. 53 00:03:47,210 --> 00:03:49,610 And then I'm going to get another one. 54 00:03:49,610 --> 00:03:53,780 Say that same name plus game mode. 55 00:03:55,280 --> 00:04:00,870 So now I have all of these Namik copies some more stuff but I have to copy that little bit on the top. 56 00:04:00,890 --> 00:04:03,380 Everybody gets to be a kid. 57 00:04:03,380 --> 00:04:11,730 You can sort of extension copy that to everyone and take a moment to reset and to make tiles. 58 00:04:12,050 --> 00:04:17,200 And then I'm going to go out of your control take the reset I can put it in the Reset. 59 00:04:17,200 --> 00:04:18,960 So if we haven't already done this now. 60 00:04:19,010 --> 00:04:22,910 Now it's a lot cooler and easier for it. 61 00:04:22,940 --> 00:04:28,670 There are many advantages to it is a lot cleaner is easier to hand this over to a colleague or someone 62 00:04:28,670 --> 00:04:29,540 who works with you. 63 00:04:29,570 --> 00:04:34,910 Also for me when I'm teaching it's a lot easier to show you things that are only in this one file and 64 00:04:34,910 --> 00:04:37,220 they all fit within one screen. 65 00:04:37,250 --> 00:04:42,620 So there's a lot of advantages of doing that and I really recommend you guys doing it so that you can 66 00:04:42,630 --> 00:04:46,430 turn when I caught the game more action put it in the game mode. 67 00:04:46,460 --> 00:04:51,200 Again this is the function we haven't done but if you'll be doing it hopefully sometime soon in the 68 00:04:51,200 --> 00:04:53,080 next few lessons. 69 00:04:53,360 --> 00:04:57,650 And let's go ahead and see what else we have we have the game. 70 00:04:57,770 --> 00:05:02,310 Make tiles this function make toys. 71 00:05:02,330 --> 00:05:08,730 Already it is quite long and I personally don't like very long functions and nobody in the programming 72 00:05:08,730 --> 00:05:10,280 world makes it so. 73 00:05:10,420 --> 00:05:14,400 Down down the end of the course when we talk about the advanced topics. 74 00:05:14,400 --> 00:05:20,960 I'm actually going to change these when I break it into several pieces so it's easier to read essentially. 75 00:05:21,060 --> 00:05:27,840 So now my view controller only has a declaration of variables and that is something you cannot put in 76 00:05:27,840 --> 00:05:29,280 a separate extension. 77 00:05:29,340 --> 00:05:33,010 They must be here in the body of the controller class. 78 00:05:33,120 --> 00:05:35,930 But then I have the resets I have the game. 79 00:05:36,180 --> 00:05:39,050 I have to make tiles which is a state a long record. 80 00:05:39,180 --> 00:05:42,510 I have to randomize which is very nice and tidy and clean. 81 00:05:42,510 --> 00:05:47,700 I have the timer function which is perfect and I have the view that law that calls a few things for 82 00:05:47,700 --> 00:05:51,220 me and it still is quite tidy and clean and easy to read. 83 00:05:51,390 --> 00:05:53,460 So that's all I wanted to do in this list. 84 00:05:53,460 --> 00:05:59,890 And like I said no new programming just adding new stuff into a group of differing class extensions. 85 00:06:00,030 --> 00:06:05,560 So they're going to help us categorize politician or more problematic term of modularize. 86 00:06:05,880 --> 00:06:09,600 Our code is keep it up to here and we'll move on to our next lesson.