1
00:00:00,560 --> 00:00:06,770
In this system you're going to talk about a very powerful you know tool in swift that is called God.

2
00:00:06,790 --> 00:00:13,420
God is essentially a way for us to validate information validate is specifically optional informational

3
00:00:13,450 --> 00:00:16,230
optional attributes or variables.

4
00:00:16,270 --> 00:00:23,380
So let's go ahead and do that in school and then it's called and start a new project my new project

5
00:00:23,440 --> 00:00:28,300
I'm going to call it Gordon it is swift.

6
00:00:28,300 --> 00:00:30,510
Now imagine a situation like this.

7
00:00:30,550 --> 00:00:39,460
Imagine you have than me take those out and have an optional one which is a string optional.

8
00:00:39,700 --> 00:00:42,750
But it does have a value for instance.

9
00:00:43,050 --> 00:00:47,710
And then I have these three times I have optional two and I have optional three.

10
00:00:47,830 --> 00:00:56,180
And then my optional to says hello vor the optional says of Vios.

11
00:00:56,230 --> 00:01:02,020
So I have three values but they are all options and I cannot be sure if they actually have a value in

12
00:01:02,020 --> 00:01:02,820
them or not.

13
00:01:02,950 --> 00:01:11,770
So the current way of doing it what you already know is doing this saying if that lets up one that's

14
00:01:12,070 --> 00:01:14,680
being optional one.

15
00:01:14,680 --> 00:01:18,870
Now imagine this a situation that they needed all three of them to be correct.

16
00:01:18,880 --> 00:01:29,300
So I'm going to have to say well if that was the case and if left up to to become my optional too and

17
00:01:29,310 --> 00:01:37,420
if that was the case one if let's of tree be my optional tree of course.

18
00:01:37,510 --> 00:01:40,240
And even that was valid as well.

19
00:01:40,240 --> 00:01:45,280
I don't know let's say print printed this pranged

20
00:01:48,430 --> 00:01:51,570
and then let's concatenate all of them together.

21
00:01:51,700 --> 00:02:01,130
All right let's concatenate them with the spaces so hello world of us it would be up 1 of.

22
00:02:01,750 --> 00:02:06,070
And not like that up to up to 3.

23
00:02:06,350 --> 00:02:07,070
All right.

24
00:02:07,090 --> 00:02:13,150
And there's really nothing wrong with doing it this is just that it's a very it's a very messy way of

25
00:02:13,150 --> 00:02:17,380
writing things you know and trying to have an error in here as well.

26
00:02:17,790 --> 00:02:18,340
Yes.

27
00:02:18,400 --> 00:02:25,990
So it's a very messy way of writing things essentially having so many you know nested if statements

28
00:02:25,990 --> 00:02:31,600
that they all work together and then it kind of makes things quite quite messy.

29
00:02:31,720 --> 00:02:36,020
So an alternative for this situation is something called God.

30
00:02:36,030 --> 00:02:45,640
So I'm going to say God is my God I'm going to say these are the things I want to god let's all one

31
00:02:45,660 --> 00:02:52,950
not be optional one and you can choose the type of faith for instance as a string.

32
00:02:53,230 --> 00:02:58,480
You know I'm going to say I want to know if it is this thing or not and then I'm going to have to say

33
00:02:58,540 --> 00:02:59,680
and another god

34
00:03:02,580 --> 00:03:07,840
and two and three and then this is going to be my two and this is going to be my tree.

35
00:03:07,840 --> 00:03:10,180
So when they got these two.

36
00:03:10,190 --> 00:03:11,120
All right.

37
00:03:11,290 --> 00:03:19,360
Otherwise do something else otherwise decide about you know are removing them or deleting them or anything

38
00:03:19,360 --> 00:03:20,380
of the sort.

39
00:03:20,380 --> 00:03:26,050
So what's happening is this I'm saying well there is something called up one which is optional one as

40
00:03:26,050 --> 00:03:26,640
a string.

41
00:03:26,710 --> 00:03:32,630
If that thing exists guard it and then got up to and then got up to the.

42
00:03:32,770 --> 00:03:38,730
And then if all three of them are working come here to this line you know do whatever you have to do

43
00:03:38,730 --> 00:03:44,310
is do something right through this thing that we wanted to do.

44
00:03:44,310 --> 00:03:48,240
Preens all of these values are there voice.

45
00:03:48,250 --> 00:03:52,780
You have to go out now going out or doing your return.

46
00:03:52,780 --> 00:04:00,310
It means that we have to somehow be within a body of a function or a for loop or something of that sort.

47
00:04:00,310 --> 00:04:08,410
So I'm actually going to put everything inside a function and then I say my God and My God essentially

48
00:04:08,410 --> 00:04:09,610
does this.

49
00:04:09,700 --> 00:04:10,480
All right.

50
00:04:10,480 --> 00:04:16,450
Let me read them to rethink that me clean all the code and only go with the things we absolutely need.

51
00:04:16,450 --> 00:04:18,780
So they begin making more sense.

52
00:04:18,790 --> 00:04:19,310
All right.

53
00:04:19,480 --> 00:04:21,680
So I have two optional values.

54
00:04:21,730 --> 00:04:25,810
All right my three optional values and guarding them by the time.

55
00:04:25,810 --> 00:04:26,500
Right.

56
00:04:26,740 --> 00:04:32,240
And I'm saying if that wasn't the case just return otherwise do that.

57
00:04:32,240 --> 00:04:38,620
So you're saying that having a set of myths that you feel statements or if statements that each of them

58
00:04:38,620 --> 00:04:44,110
depends on the previous one and the previous one the previous one and guarding as many values that I

59
00:04:44,110 --> 00:04:49,600
want and then if they are all OK then I get to here to do whatever I want to do.

60
00:04:49,600 --> 00:04:52,470
If one of them fails I just retire.

61
00:04:52,480 --> 00:04:59,530
So this is very useful for situations where the life of several variables depends on each other.

62
00:04:59,530 --> 00:05:05,600
If you're read information from a network and every bit of information must be there before you can

63
00:05:05,600 --> 00:05:11,720
present it or anything of that nature in the next lesson or we're going to actually use this god for

64
00:05:11,720 --> 00:05:16,640
reading information into something called a convenience in its art.

65
00:05:16,850 --> 00:05:21,590
This thing here the warning don't worry about it simply because it is saying that the value you are

66
00:05:21,590 --> 00:05:24,990
trying to convert is of the type of string.

67
00:05:25,130 --> 00:05:27,330
So definitely this we always succeed.

68
00:05:27,440 --> 00:05:33,770
But in real life scenarios we usually don't read or optionals from value but that we know what they

69
00:05:33,770 --> 00:05:40,010
are we might be reading them from things that we're not sure what kind of nature they have.

70
00:05:40,220 --> 00:05:45,480
So based on that let's keep it up to here and we'll move on to our next lesson.
