WEBVTT 00:06.810 --> 00:13.530 In this video you're going to learn cities and guessers in Essex cities and ghettos are used to either 00:13.530 --> 00:19.320 says the value of faces and property or retrieve it now in iOS 5. 00:19.350 --> 00:24.930 You had a certain form of citizen guesses but the syntax in iOS 6 is a lot simpler. 00:24.930 --> 00:28.580 So we're not gonna cover the syntax in S5. 00:28.620 --> 00:32.050 We'll only focus on the syntax in iOS 6. 00:32.670 --> 00:35.670 So let's create an example. 00:35.910 --> 00:37.310 So it starts with a setter. 00:38.370 --> 00:39.770 So the syntax is easy. 00:39.780 --> 00:45.120 So you use the keyword followed by the name of the setter. 00:45.690 --> 00:50.510 So you gonna use the same name as the property name. 00:50.910 --> 01:02.770 Now later on if you write something like this. 01:03.050 --> 01:14.250 So an instance of the class dots the setter then you set it to something like 30. 01:14.670 --> 01:19.200 Then this will automatically call the set method. 01:19.390 --> 01:20.320 Right. 01:20.460 --> 01:24.990 So calling the warranty we'll call the method warranty. 01:24.980 --> 01:25.280 All right. 01:25.770 --> 01:27.480 So we can prove that by 01:31.160 --> 01:36.980 adding a console log they're saying that's the warranty has been set to something. 01:37.970 --> 01:41.660 So warranty said 2 X 01:45.770 --> 01:51.920 for example and then we can sense the warranty to X.. 01:51.940 --> 01:59.780 So with this boat warranty equals x. 01:59.820 --> 02:03.750 Now if you try this like lens you're gonna get an error 02:15.550 --> 02:16.560 okay. 02:16.730 --> 02:23.170 So the reason why is because the maximum call stuck size has been exceeded. 02:23.570 --> 02:31.190 So you can see that this is very similar to a loop on an infinite loop. 02:31.190 --> 02:35.210 The reason why you get that loop is because when you run this method 02:38.520 --> 02:41.170 you call this dot warranty. 02:41.400 --> 02:48.300 You said it's something and this will call the set method because we say that if you call Dot's warranty 02:48.300 --> 02:51.570 equals something you call in the says This is method. 02:51.570 --> 02:54.090 So this will call this method again. 02:54.090 --> 03:00.960 And then you go inside and then this does warranty call this method and you go back up again and the 03:00.960 --> 03:03.060 loop is infinite. 03:03.090 --> 03:11.840 Now we need a way to fix this so to fix that instead of calling this Dot's warranty we need to change 03:11.930 --> 03:13.160 this syntax. 03:13.160 --> 03:16.760 So instead of both warranty we need something else. 03:16.790 --> 03:17.640 So what are we going to do. 03:17.660 --> 03:21.090 We will just change the name of the property warranty. 03:21.440 --> 03:26.810 So instead of warranty we're going to have underscore warranty we're going to take this everywhere. 03:31.230 --> 03:32.710 All right. 03:32.760 --> 03:35.700 So now if you try this 03:38.650 --> 03:39.460 it works this time. 03:40.600 --> 03:47.970 And when you call that it's called the it says method and you get a warranty set to 30 right. 03:47.990 --> 03:50.050 And this time it's working perfectly 03:52.680 --> 04:03.470 now let's move to the get method where we get a. 04:04.010 --> 04:13.550 So it it's gonna be very similar to the set method instead of says we're gonna use get no property needed 04:13.880 --> 04:18.510 or no argument needed and they just log 04:21.820 --> 04:23.720 gets warranty called 04:26.620 --> 04:34.120 and it s is going to return this dot policy. 04:35.090 --> 04:35.960 So now let's 04:38.940 --> 04:44.400 log my phone six dots one and see 04:47.230 --> 04:52.980 you get thirsty and you can see that the get one that gets method has been called. 04:53.330 --> 04:59.800 All right so this one calls the setter. 04:59.900 --> 05:03.670 This one calls we get 05:07.840 --> 05:16.550 now let's do something interesting so let's add another property to the class is called it. 05:16.570 --> 05:26.970 Look and let's say that whenever you said something to the object you just log that change 05:29.760 --> 05:35.210 so instead of logging warrants is set to X we'll just take this and 05:38.540 --> 05:44.040 add it to the log array like this. 05:44.060 --> 05:55.580 So now if you change the warranty to 30 and then you change it to 40 then back to 30 for example at 05:55.580 --> 06:02.360 the end if you log my phone six dots log 06:05.100 --> 06:08.670 then you get the full log of all the settings. 06:08.670 --> 06:09.950 So he says she says he. 06:09.960 --> 06:11.330 Then you said he's a 4c. 06:11.370 --> 06:12.730 Then he says it is easy. 06:12.810 --> 06:18.900 That's an interesting example showing how the set method can be used. 06:18.900 --> 06:24.060 All right so hopefully this gave you a good understanding all senses and guesses in E6.