1
00:00:00,650 --> 00:00:02,870
So good morning and welcome back.

2
00:00:03,050 --> 00:00:08,570
I assume it is morning for you as well because it's morning for me so I got it all where you are.

3
00:00:08,570 --> 00:00:09,320
Welcome back.

4
00:00:09,320 --> 00:00:13,550
And in this listen I'm going to show you how to use IAB outlets connections.

5
00:00:13,610 --> 00:00:20,360
I built those connections on a way for us to cluster a series of outlets with each other when they have

6
00:00:20,360 --> 00:00:27,460
commonalities between them a good example of it would be something like a rating that you have a Stars

7
00:00:27,490 --> 00:00:29,720
and three star rating situation.

8
00:00:29,720 --> 00:00:32,460
You have all of these stars maybe five of them.

9
00:00:32,530 --> 00:00:38,330
Or for example I'm going to show you something like a radio by then that you have multiple buttons they

10
00:00:38,330 --> 00:00:43,480
have a similar nature and then you want to have all of them between the same outlets.

11
00:00:43,490 --> 00:00:46,730
So let's go ahead and to explore and see how we're going to do that.

12
00:00:46,730 --> 00:00:56,450
I'm going to go ahead and open export and then say I have a new application called My b outlet collection

13
00:00:56,560 --> 00:01:03,090
app and yet I'm gonna head to my storyboard and in this storyboard I'm actually going to go ahead and

14
00:01:03,090 --> 00:01:05,010
make a few buttons.

15
00:01:05,010 --> 00:01:10,730
I'm gonna go ahead and say this is a button now for my buttons.

16
00:01:10,740 --> 00:01:18,360
I want them to have a look of a radio by then unluckily in swift and essentially a Mac OS we could do

17
00:01:18,360 --> 00:01:18,910
this.

18
00:01:18,930 --> 00:01:24,880
I'm going go in here and say control command then a space and then I can get these emojis.

19
00:01:25,020 --> 00:01:30,720
And there's actually two of them that they found that are actually like the buttons white circle and

20
00:01:30,720 --> 00:01:31,590
radio button.

21
00:01:31,590 --> 00:01:34,160
They look very similar to what I want.

22
00:01:34,230 --> 00:01:36,790
So I'm going to place a white circle in it.

23
00:01:36,840 --> 00:01:38,560
So that's one.

24
00:01:38,940 --> 00:01:42,390
And then what I'm gonna do is I'm going to make five copies of these.

25
00:01:42,390 --> 00:01:44,940
So these are the radio buttons.

26
00:01:44,940 --> 00:01:46,860
So this is that her step forward.

27
00:01:46,890 --> 00:01:48,000
And this is the fifth.

28
00:01:48,140 --> 00:01:54,120
And if you recall the best approach for doing something like this would be a horizontal stack view.

29
00:01:54,660 --> 00:01:57,910
So I will go in here and say thank you.

30
00:01:58,130 --> 00:02:00,330
And I want to get a horizontal one.

31
00:02:00,330 --> 00:02:06,240
You could of course select all of these and using this little button here you could actually embed them

32
00:02:06,270 --> 00:02:08,580
within a stack view.

33
00:02:08,610 --> 00:02:12,930
But what I'm going to do is I'm going to make it manually so I can see what I'm doing.

34
00:02:12,930 --> 00:02:20,090
So for each of these I'm going to assume they have a height that is all based 64 so that's that.

35
00:02:20,100 --> 00:02:25,710
So let's go ahead and say that's the height and I want it to be a stuck to the left than the right side.

36
00:02:25,710 --> 00:02:30,350
So I'm going to say leading a space that is going to be zero.

37
00:02:31,020 --> 00:02:40,980
A trailing space that also is going to be zero and a top a space to the container or to a safe area

38
00:02:41,040 --> 00:02:44,470
which is let's say a hundred forty four that's OK.

39
00:02:44,520 --> 00:02:46,630
So that's where I have my stack.

40
00:02:46,650 --> 00:02:52,110
You now I'm going to select all of these guys drive them into my snack view and just like view as default

41
00:02:52,170 --> 00:02:53,930
behavior is not what they want.

42
00:02:53,990 --> 00:02:55,140
A new one is this.

43
00:02:55,140 --> 00:02:58,190
I want them to be distributed evenly.

44
00:02:58,200 --> 00:03:02,910
So I'm going to say feel equally and that's kind of what I want to have.

45
00:03:02,970 --> 00:03:04,580
Let me see if there's a better one.

46
00:03:04,590 --> 00:03:08,240
Is there a feel proportionally an equal spacing.

47
00:03:08,390 --> 00:03:14,310
No the equal spacing actually pushes them to the right and left which is not what they want.

48
00:03:14,580 --> 00:03:18,270
I think that the one was okay feel proportionally.

49
00:03:18,480 --> 00:03:20,550
So I have the five buttons in here.

50
00:03:20,550 --> 00:03:22,100
Now the next thing is this.

51
00:03:22,260 --> 00:03:29,430
If I select one of these guys and I go to my assistant window gets rid of all of those gets rid of the

52
00:03:29,430 --> 00:03:36,920
view that load the default behavior that we have been using is doing a controlled drag and in here seeing

53
00:03:36,930 --> 00:03:40,020
an outlet which is what we have been doing forever.

54
00:03:40,170 --> 00:03:47,750
But now when I say make an outlet collection and I'm going to call this one my buttons.

55
00:03:47,880 --> 00:03:49,370
Now let's see what it makes.

56
00:03:49,380 --> 00:03:51,960
Essentially this is what matters in here.

57
00:03:51,960 --> 00:03:58,860
It says well I outlet my event my buttons is an array of UI dance.

58
00:03:59,190 --> 00:04:04,170
So it's essentially an array of the type of the object you're trying to make.

59
00:04:04,170 --> 00:04:10,650
In this case being you I by that's the next thing I'm going to have to do is I have to go to my interface

60
00:04:10,650 --> 00:04:15,340
builder and connect this my buttons outlet to all of my buttons.

61
00:04:15,350 --> 00:04:21,570
So when I go to the storyboard and in here I'm going to select my view controller in here and then go

62
00:04:21,570 --> 00:04:27,460
to the connections in the connections that you already have my buttons that connects to one of the buttons.

63
00:04:27,480 --> 00:04:32,490
So I'm going to have to connect that to all of them select that and drag it in here select and then

64
00:04:32,490 --> 00:04:37,110
I go over here select and then I go over here and select and then I go over here.

65
00:04:37,110 --> 00:04:43,370
Now my body's outlet collection is actually connecting to five different buttons in here.

66
00:04:43,410 --> 00:04:48,060
Now what happens when we tap on one of these what happens when we want to trigger an action.

67
00:04:48,090 --> 00:04:53,010
So for that we need an action coming here I'll say one of my buttons.

68
00:04:53,040 --> 00:05:01,170
Let's say this top one where did I get over here and say I have an action and for the action I'm going

69
00:05:01,170 --> 00:05:03,040
to call it tap.

70
00:05:03,510 --> 00:05:11,980
Action so I have one of the actions now I know I'm going to head back to my storyboard and say let's

71
00:05:11,980 --> 00:05:14,460
connect this one action to everyone.

72
00:05:14,470 --> 00:05:20,540
So the action that says top action this one is connected to this guy.

73
00:05:20,560 --> 00:05:28,700
Touch up in the side that's connected to the next guy touch up inside the fourth guy.

74
00:05:28,890 --> 00:05:33,580
Touch up inside and the fifth guy touch up inside.

75
00:05:33,600 --> 00:05:36,660
Now pay attention that this isn't a new thing.

76
00:05:36,720 --> 00:05:38,520
We could have done this even in the past.

77
00:05:38,520 --> 00:05:43,760
We could connect the same function to multiple bodies we probably even did that in the past.

78
00:05:43,890 --> 00:05:45,850
But this part of it is a new thing.

79
00:05:45,870 --> 00:05:49,350
Having one outlet that has multiple items in it.

80
00:05:49,950 --> 00:05:57,950
Now let's go ahead into our top section and do something with in year the first thing I'm gonna do is

81
00:05:57,950 --> 00:06:00,200
just to simplify my life is this.

82
00:06:00,200 --> 00:06:07,910
I'm gonna say send there is always a new eye by then because I know it is a UI but then the only items

83
00:06:07,940 --> 00:06:11,260
that are actually calling this action are the UI buttons.

84
00:06:11,300 --> 00:06:20,270
The next thing is I want to make the send there to show me the set title that by then that is actually

85
00:06:20,270 --> 00:06:20,960
pressed.

86
00:06:21,020 --> 00:06:25,080
So for that I'm gonna say Give me that thing again.

87
00:06:25,090 --> 00:06:29,040
The emojis within the emojis I'm going to choose the selected one.

88
00:06:29,060 --> 00:06:30,290
So that's the radio by then.

89
00:06:30,290 --> 00:06:34,720
That is already selected and this state is a normal state so normal.

90
00:06:34,970 --> 00:06:41,090
Now the problem is this Every time we tap on one of these buttons that one is going to become selected.

91
00:06:41,090 --> 00:06:48,230
But prior to that we have to make everyone on select that simply because we can't have more than one

92
00:06:48,230 --> 00:06:49,830
currently being selected.

93
00:06:50,030 --> 00:06:54,510
So I'm going to go ahead and say 4 and I'm going to call it any.

94
00:06:54,510 --> 00:07:02,420
By then in my by Dennis simply because that's an array so I'm going to say for anybody my by Dems say

95
00:07:02,510 --> 00:07:08,060
any by then set title the exact same thing as we did before.

96
00:07:08,060 --> 00:07:14,840
Except that this time we're going to select the on selected emoji or this icon which is the circle.

97
00:07:15,260 --> 00:07:20,690
So I'm going to say make everyone be on the selected for the same estate of normal.

98
00:07:21,380 --> 00:07:27,130
And then once you're done with that make this particular guide the sender gonna make it selected.

99
00:07:27,140 --> 00:07:29,060
Now let's see all of this in practice.

100
00:07:29,060 --> 00:07:34,910
If it all works well we should be able to see all four buttons to become on selected on one of them

101
00:07:34,910 --> 00:07:35,960
to get selected.

102
00:07:36,770 --> 00:07:42,260
I think I was doing the designs on iPhone 8 and I'm running the simulation iPhone 10.

103
00:07:42,260 --> 00:07:44,930
It doesn't really make a difference in this case.

104
00:07:44,960 --> 00:07:50,920
Now I have that I can select and I can make one of them to become the way I wanted it to be.

105
00:07:50,960 --> 00:07:56,060
So that's working all well maybe I can change the background color in here so we can see a little bit

106
00:07:56,060 --> 00:08:02,420
of a different you know color in here and that's actually a good exercise because it's not as easy as

107
00:08:02,420 --> 00:08:04,280
you might think with a stack of views.

108
00:08:04,440 --> 00:08:10,100
A like you don't have a mechanism for us to change their background color even if you do change the

109
00:08:10,100 --> 00:08:11,260
background color.

110
00:08:11,270 --> 00:08:14,690
It doesn't really reflect anybody it doesn't show it to you anywhere.

111
00:08:14,750 --> 00:08:19,940
So what you have to do is you have to embed your snack view within a few iView.

112
00:08:20,030 --> 00:08:26,660
So here's one when I do I'm going to say a few eye view and this UI view and when I place it let's say

113
00:08:26,660 --> 00:08:27,050
here.

114
00:08:27,080 --> 00:08:32,340
I mean ideally you would put it where you wanted to put it but for now I'm just going to get somewhere.

115
00:08:32,690 --> 00:08:39,860
I will say the height of it has a constant value of just like the last time 64.

116
00:08:40,790 --> 00:08:47,970
I'm going to say it has a leading and a trailing and it has a top a space that is like this.

117
00:08:48,050 --> 00:08:54,500
So not only got that and my you I view is in here I could go ahead and say change this background color

118
00:08:54,710 --> 00:09:01,340
to light grey for instance something like that yet I'm gonna grab my snack view and make it a child

119
00:09:01,430 --> 00:09:02,690
of my view.

120
00:09:02,690 --> 00:09:08,140
Now a child of my view is going to break a lot of the concept constraints so they had for this snack

121
00:09:08,140 --> 00:09:08,680
view.

122
00:09:08,720 --> 00:09:11,240
The only thing that's maintained is 64.

123
00:09:11,240 --> 00:09:13,300
So you have to redo this.

124
00:09:13,370 --> 00:09:20,690
I'm going to go ahead and say the stage for has a leading a space has a trading space has the same Vette

125
00:09:21,170 --> 00:09:27,290
and has the same height and I won't need this height anymore because its height is being controlled

126
00:09:27,290 --> 00:09:29,120
with a different constraint.

127
00:09:29,630 --> 00:09:33,170
So let's go to our snack for you and change those constraints.

128
00:09:33,170 --> 00:09:36,820
I'm gonna say the trailing his face is zero.

129
00:09:36,860 --> 00:09:42,890
I'm gonna say leading a space is zero an equal width and height are gonna make sure that my snack view

130
00:09:42,890 --> 00:09:45,620
is always within my UI view.

131
00:09:45,620 --> 00:09:52,210
If I change the color of my UI view to say a green color you will automatically see it there.

132
00:09:52,520 --> 00:09:56,410
If I change it to a darker reddish color we see it there.

133
00:09:56,580 --> 00:10:02,510
And if we run the application now my UI view is going to find its place within the view the main view

134
00:10:02,960 --> 00:10:08,030
and then the sky tree is gonna find this place within the UI view and everything is exactly the way

135
00:10:08,060 --> 00:10:14,750
we were hoping it will be we top on one button that button nearly always everywhere the earth and itself

136
00:10:14,780 --> 00:10:17,900
becomes selective so that's it.

137
00:10:17,900 --> 00:10:23,390
A quick introduction on how to use IP outlets collections they are useful for when you have objects

138
00:10:23,390 --> 00:10:28,420
of the same nature and you want them all to be somehow correlated to each other.

139
00:10:28,460 --> 00:10:34,340
Examples of it are things such as when you have a star rating radio buttons.

140
00:10:34,430 --> 00:10:39,590
If you have a group of labels that they all have to be I don't know animated within a game and you want

141
00:10:39,590 --> 00:10:42,100
to have access to all of them within an array.

142
00:10:42,140 --> 00:10:47,000
Any situation that you can imagine that you want your objects to be within an array.

143
00:10:47,000 --> 00:10:51,050
That's a good place for having an IAB outlet collection.

144
00:10:51,080 --> 00:10:58,740
Now if you remember in our one of our previous sections where we did a game in that game I made an array

145
00:10:58,740 --> 00:11:02,090
of all the labels or an array of all the images.

146
00:11:02,160 --> 00:11:07,590
So that's a very similar concept except that there it wasn't an IEP outlet.

147
00:11:07,590 --> 00:11:09,200
It was merely an outlet.

148
00:11:09,210 --> 00:11:14,450
It was a variable might by then of the type array of UI buttons.

149
00:11:14,460 --> 00:11:17,970
This is the same thing within Interface builder on a storyboard.

150
00:11:18,540 --> 00:11:21,360
So let's keep it up to here and move on to our next lesson.
