1
00:00:01,160 --> 00:00:08,020
Not come back again this is the last lesson of this group of lessons which deal with view controllers

2
00:00:08,050 --> 00:00:11,270
on segues and passing data or so on and so forth.

3
00:00:11,480 --> 00:00:16,690
So in this listen we're going to pass some information between one view controller to the other.

4
00:00:17,060 --> 00:00:18,830
Let's see how we could do that.

5
00:00:18,830 --> 00:00:23,650
I'm going to go into ex-cult and disclose this application.

6
00:00:23,660 --> 00:00:30,550
I'm going to make a new application called passing data.

7
00:00:31,160 --> 00:00:33,880
I never learned whether it is data or data.

8
00:00:33,890 --> 00:00:37,700
It seems like a lot of people just call it data data.

9
00:00:37,700 --> 00:00:40,130
So just up you can go live if you like too.

10
00:00:40,130 --> 00:00:44,120
So for me it is for the most part data.

11
00:00:44,390 --> 00:00:48,560
So here I have one view controller understand we're going to do things an easier way.

12
00:00:48,560 --> 00:00:55,880
I'm going to add another view controller on this new view controller is going to have a slightly different

13
00:00:55,880 --> 00:00:58,630
background colors such as this one.

14
00:00:58,880 --> 00:01:06,950
And I have a new class for the new class for it is called Pinkard View Controller of the type you view

15
00:01:06,950 --> 00:01:15,140
controller course and now most of the files are here the pink ones are now going to go into my storyboard

16
00:01:15,590 --> 00:01:22,200
select this control outlet go to the identity and call it Change view control.

17
00:01:22,220 --> 00:01:22,950
Perfect.

18
00:01:23,210 --> 00:01:29,750
So the next thing is I'm actually going to go ahead in here and I'm going to ride from my view controller

19
00:01:29,840 --> 00:01:38,240
into the pink one and say man he take a show and my segment is called the identifier for it is called

20
00:01:38,750 --> 00:01:44,380
to say a id you could call it anything you would call it.

21
00:01:44,380 --> 00:01:48,670
Pete I would I'd rather give it more meaningful names.

22
00:01:48,680 --> 00:01:51,480
I did multiple endos and I removed that.

23
00:01:51,480 --> 00:01:54,130
So here's a chance to see it once again.

24
00:01:54,140 --> 00:01:58,460
So identifier to ping.

25
00:01:58,650 --> 00:02:00,440
Say today Heidi.

26
00:02:00,520 --> 00:02:01,010
All right.

27
00:02:01,010 --> 00:02:02,330
So I've got that.

28
00:02:02,330 --> 00:02:03,860
So here's what they want to happen.

29
00:02:03,860 --> 00:02:06,420
Here's what they want to pass essentially.

30
00:02:06,650 --> 00:02:11,290
I want to have a text field in here so I have this textfield.

31
00:02:11,630 --> 00:02:19,040
So whenever I go to this very first few controller or of view controller or main or view controller

32
00:02:19,430 --> 00:02:26,810
whenever I come in here and I enter something in this text Vindt a y to be passed into the into the

33
00:02:26,810 --> 00:02:27,510
pink one.

34
00:02:27,550 --> 00:02:31,990
So go ahead and have this textfield in here.

35
00:02:32,270 --> 00:02:38,540
And then I have a button and this obviously is going to take us to that pink view controller.

36
00:02:38,620 --> 00:02:43,350
So I'm going to modify it a little bit with a different background color.

37
00:02:43,460 --> 00:02:49,300
It says go to Penkridge And then what's happening in the pink one.

38
00:02:49,310 --> 00:02:55,300
I have one label that is going to show us what we receive from the other side.

39
00:02:55,310 --> 00:03:00,670
So the label is going to show us whatever information we have received from the white one.

40
00:03:00,710 --> 00:03:02,670
So here that's my label.

41
00:03:02,810 --> 00:03:04,800
Let's call it the receive.

42
00:03:04,930 --> 00:03:05,790
That's all.

43
00:03:05,930 --> 00:03:08,290
That's just the text in that it doesn't mean anything.

44
00:03:08,480 --> 00:03:14,410
So I'm going to change his color maybe like that so we can see and of course I need a back then.

45
00:03:14,450 --> 00:03:16,350
So I'm going to add a button in.

46
00:03:16,430 --> 00:03:19,520
Say back.

47
00:03:20,060 --> 00:03:20,630
OK.

48
00:03:20,660 --> 00:03:25,100
So that's going back and maybe it's by gone is a different color.

49
00:03:25,250 --> 00:03:27,110
So now I've got everything that I need.

50
00:03:27,110 --> 00:03:32,010
So all I have to do is I have to add the functions and also the outlets for them.

51
00:03:32,180 --> 00:03:35,460
So let's go to our assistant.

52
00:03:35,630 --> 00:03:41,390
I'm going to go to the View Controller up here in the view Control read that h I'm going to drag this

53
00:03:41,390 --> 00:03:47,520
one I'm going to call this one data off text the.

54
00:03:47,720 --> 00:03:52,430
So that's my daughter textfield and of course I have to have a function.

55
00:03:52,460 --> 00:03:57,470
This one says go to pink action.

56
00:03:57,470 --> 00:04:03,160
And I remember the type has to be action to go to a peeing action.

57
00:04:03,170 --> 00:04:03,660
Perfect.

58
00:04:03,670 --> 00:04:06,200
I've got that taking care of in here.

59
00:04:06,230 --> 00:04:09,930
I need to how my pinky contorted that age.

60
00:04:10,090 --> 00:04:10,850
I'm in it.

61
00:04:10,880 --> 00:04:13,470
I'm going to get rid of everyone I know I don't need.

62
00:04:13,670 --> 00:04:18,250
But they do need however is this one of them is this label.

63
00:04:18,290 --> 00:04:19,250
I'm going to call it.

64
00:04:19,250 --> 00:04:23,350
I actually received that on the label.

65
00:04:23,390 --> 00:04:27,110
So it's the doctors that receive the connect.

66
00:04:27,130 --> 00:04:29,540
And I need a function that is very simple.

67
00:04:29,540 --> 00:04:37,010
We have done multiple times before and that one says go back home action.

68
00:04:37,120 --> 00:04:41,610
And I remember it's connection is of that type action.

69
00:04:41,740 --> 00:04:44,020
So that's about that.

70
00:04:44,020 --> 00:04:44,590
All right.

71
00:04:44,620 --> 00:04:49,320
So now I have to go on and write the code that is going to help me pass that.

72
00:04:49,380 --> 00:04:51,410
So let's go to our editor.

73
00:04:51,400 --> 00:04:53,000
I'm going to go to the control.

74
00:04:53,030 --> 00:05:00,320
I am in unity of everyone I don't need and the only thing I need to do is here in the GO took action.

75
00:05:00,340 --> 00:05:02,370
I'm going to get on this train.

76
00:05:02,530 --> 00:05:05,210
This call is to send a string.

77
00:05:05,220 --> 00:05:12,350
It is going to be on my textfield whatever I call it takes effort.

78
00:05:12,370 --> 00:05:20,000
The ad was called takes the fill the text so I'm first going to get the data that my user has entered

79
00:05:20,470 --> 00:05:34,100
and then I'm going to have to say self perform segue with identifier say with identifier and then identify

80
00:05:34,100 --> 00:05:35,500
what they want to use is.

81
00:05:35,880 --> 00:05:43,410
So the segue I want to call I remember it was called the two pink Sigge way.

82
00:05:43,680 --> 00:05:44,660
I did.

83
00:05:45,070 --> 00:05:50,360
And my sense there is going to be this information to send a stream.

84
00:05:50,500 --> 00:05:51,000
Right.

85
00:05:51,130 --> 00:05:54,170
And I oh I have made a terrible mistake stuff.

86
00:05:54,210 --> 00:05:54,660
All right.

87
00:05:54,690 --> 00:06:02,720
So now what's happening is I'm saying perform segue with this identifier and send there is this information

88
00:06:03,140 --> 00:06:04,000
right now.

89
00:06:04,260 --> 00:06:06,780
Let's see how we're going to use this information.

90
00:06:06,810 --> 00:06:14,460
Now this information cannot be used in here simply because they have to somehow go to our next viewer

91
00:06:14,490 --> 00:06:17,570
controller which in this case is the pink one.

92
00:06:17,730 --> 00:06:20,590
So let's go to our Pinku controller.

93
00:06:20,690 --> 00:06:25,230
I know this is going to seem a little bit confusing right now but I'm going to come back to it in a

94
00:06:25,230 --> 00:06:25,740
second.

95
00:06:25,740 --> 00:06:33,270
So in my pink entourage I'm going to do this I'm going to say there is a property in here property so

96
00:06:33,270 --> 00:06:42,140
I'm defining a new property of the type and a string and that property in a string is called receive

97
00:06:42,220 --> 00:06:43,910
data.

98
00:06:43,980 --> 00:06:48,200
So there is a property called and it's a string receive the data.

99
00:06:48,270 --> 00:06:52,470
And here is what happens every time our view loads.

100
00:06:52,500 --> 00:06:59,060
So you might pinch your controller you did the Lord OK.

101
00:07:00,270 --> 00:07:10,050
I'm going to go ahead and say every time that you loads do this say received Les dot text is going to

102
00:07:10,050 --> 00:07:19,530
be received the data that they received a string was that the name I gave it received.

103
00:07:19,520 --> 00:07:26,780
Dr. Yes received that that received that received that yes.

104
00:07:26,790 --> 00:07:28,430
So here's what's happening.

105
00:07:28,470 --> 00:07:28,830
All right.

106
00:07:28,830 --> 00:07:30,460
Once again off the top.

107
00:07:30,470 --> 00:07:30,940
Right.

108
00:07:31,060 --> 00:07:39,330
We are saying every time the controller loads in the view the Lord make that label textile you showed

109
00:07:39,330 --> 00:07:41,500
this guy received the data.

110
00:07:41,570 --> 00:07:46,890
Is this guy received that is actually a property in our Pinheiro you controller.

111
00:07:46,920 --> 00:07:49,570
It is not that age which means it's also in our.

112
00:07:49,600 --> 00:07:57,900
And now we have to somehow connect this received data to the value that we have in a sense there from

113
00:07:57,930 --> 00:07:59,810
our segue.

114
00:07:59,970 --> 00:08:01,910
So let's see how are we going to do that.

115
00:08:01,920 --> 00:08:05,750
I'm actually going to quickly clean everything up every everyone I don't need.

116
00:08:05,790 --> 00:08:13,200
So in my dad's age I need everything in my view contorted that I don't need to view that lot in my opinion

117
00:08:13,220 --> 00:08:14,550
you can tell at that age.

118
00:08:14,550 --> 00:08:19,820
I need everybody who is there that's the label that's the action for going back and that's the property

119
00:08:19,820 --> 00:08:25,260
we just declared and the viewpoint that I'm with I'm going to do is I'm going to change this.

120
00:08:25,260 --> 00:08:30,280
Go back home to something that we know for a while and I dismiss you.

121
00:08:30,280 --> 00:08:32,740
Controller are animated.

122
00:08:32,740 --> 00:08:33,520
True.

123
00:08:33,890 --> 00:08:36,180
Do nothing to completion.

124
00:08:36,180 --> 00:08:38,370
So that's a simple as that.

125
00:08:38,400 --> 00:08:45,960
So Harvey going to connect this received data outside this received data to the value that we have in

126
00:08:45,960 --> 00:08:46,910
the sender.

127
00:08:46,950 --> 00:08:51,550
For that we need a separate method and that method is a member of the UI kit.

128
00:08:51,560 --> 00:08:52,120
It's all.

129
00:08:52,170 --> 00:09:00,420
It always exists within all of view controllers and that is called that prepare for Segway.

130
00:09:00,720 --> 00:09:02,750
So let's see what this one does.

131
00:09:02,790 --> 00:09:09,270
It says if you are going to run a Segway let's do some preparation for it.

132
00:09:09,270 --> 00:09:09,650
All right.

133
00:09:09,660 --> 00:09:13,340
So what are those preparations the preparations that we need.

134
00:09:13,380 --> 00:09:23,520
I'm going to write them in comments is to make sure they're received receive that off from Pyncheon

135
00:09:23,540 --> 00:09:34,700
vu controller has the same information as the sender which sender it doesn't matter because the sender

136
00:09:34,710 --> 00:09:40,800
I understand are going to be identical because when we call the code pink I cautioned the sender is

137
00:09:40,800 --> 00:09:43,470
going to send the right information in to here.

138
00:09:43,470 --> 00:09:45,140
These are just names of course.

139
00:09:45,270 --> 00:09:52,380
So first thing in the prepare for C-grade which is builtin function from view controllers we are saying

140
00:09:52,380 --> 00:09:58,860
when you're preparing for a sick they make sure they received data from Pinkerton is the same as the

141
00:09:58,860 --> 00:09:59,730
sender.

142
00:09:59,760 --> 00:10:04,180
So as this guy which in this case is called a Sender.

143
00:10:04,380 --> 00:10:05,670
So how are we going to do that.

144
00:10:05,670 --> 00:10:10,290
The first thing is we need to get access for pink view controller to do that.

145
00:10:10,290 --> 00:10:15,170
I'm going to go ahead and say import ping view controller.

146
00:10:15,180 --> 00:10:21,530
So now we have access to our Pinku controller within our view controller.

147
00:10:21,540 --> 00:10:24,340
So now I'm going to say let's check the Segway.

148
00:10:24,350 --> 00:10:30,850
So because remember you might have multiple segues you know your main a storyboard might have a Segway

149
00:10:30,870 --> 00:10:35,660
that goes from the White One to the pink one and then from the right one you might go to a green one

150
00:10:35,660 --> 00:10:37,040
and so on and so forth.

151
00:10:37,200 --> 00:10:46,710
So I'm going to say if I get sick of a dot identifier is equal to a string and the string I'm looking

152
00:10:46,710 --> 00:10:48,020
for is this guy.

153
00:10:48,240 --> 00:10:55,140
If this is the same way that you're going through in this particular example in the app I'm making this

154
00:10:55,140 --> 00:11:00,820
is completely meaningless simply because I only have one the segue in in here in here.

155
00:11:01,080 --> 00:11:06,930
But in real life example on for the sake of doing things the right way you want to check for this.

156
00:11:06,930 --> 00:11:15,090
You want to say if say great is this Segway then let's get access to the view controller interview controllers.

157
00:11:15,270 --> 00:11:18,830
Let's call it this ping in stance.

158
00:11:18,840 --> 00:11:24,240
You can call it anything is a Segway destination view controller.

159
00:11:24,450 --> 00:11:32,250
So if you are saying make an make an instance of ping controller call it to this Pinkins stance and

160
00:11:32,250 --> 00:11:39,430
make that to be or a sign that to be the destination of Segway What's the destination of Segway.

161
00:11:39,450 --> 00:11:45,210
Obviously in this case is this guy this outlet in R R R A storyboard.

162
00:11:45,330 --> 00:11:51,040
This outfit itself is connected to a class called Pink fuel controller.

163
00:11:51,090 --> 00:11:59,860
So when I go back in here I'm going to say well if you did not then say this Pinkins That's dot receive

164
00:11:59,920 --> 00:12:01,020
the data.

165
00:12:01,150 --> 00:12:05,040
That's that is going to be send.

166
00:12:05,200 --> 00:12:12,220
Now since we are not sure whether the sender is an assisting or not it's of the type I.D. It helps if

167
00:12:12,210 --> 00:12:17,480
we cast it and I'm going to say and a strong scent.

168
00:12:17,540 --> 00:12:22,470
Now let's run this up once and then I'm going to rewrite this bit of the code once again.

169
00:12:22,470 --> 00:12:25,420
So it kind of you know recaps everything.

170
00:12:25,420 --> 00:12:28,920
I feel like this might be a little bit confusing for the first time.

171
00:12:29,110 --> 00:12:35,290
So let's run the app now and if it all works we should be able to get to see whatever we need on the

172
00:12:35,290 --> 00:12:36,050
other side.

173
00:12:36,110 --> 00:12:41,100
So in here I'm going to go ahead and say hello.

174
00:12:41,660 --> 00:12:44,840
I go to pink and here it says hello pinky.

175
00:12:44,860 --> 00:12:52,760
If I go back and say hello are not too blue and go to pink it says hello not blue.

176
00:12:52,800 --> 00:13:00,970
Now let's quickly see what we have done in our view control of this one the one we are going from.

177
00:13:01,160 --> 00:13:04,450
We are getting access to our paying View Controller.

178
00:13:04,570 --> 00:13:06,290
So that's one part.

179
00:13:06,430 --> 00:13:13,120
If you're getting that one and then we are saying that when you're preparing to move to the sick bay

180
00:13:13,540 --> 00:13:20,020
first check if this is the right segue or not for now because I'm trying to simplify things I'm going

181
00:13:20,020 --> 00:13:26,710
to say let's drop that whole thing simply because I know this is the right segue is only one of them

182
00:13:26,710 --> 00:13:27,730
in here anyway.

183
00:13:28,000 --> 00:13:31,800
So I'm going to say when you're preparing for the segue.

184
00:13:31,810 --> 00:13:39,880
Make it that the Sigmond destination will be assigned to something of the type Ping's you controller

185
00:13:40,300 --> 00:13:42,220
because that's what we know we need.

186
00:13:42,370 --> 00:13:48,190
So we need to think through a controller and then I'm going to say from this stance of fate Let's get

187
00:13:48,310 --> 00:13:51,970
to receive data and assign a value to it.

188
00:13:51,970 --> 00:13:53,980
Forget this whole send there for a second.

189
00:13:54,040 --> 00:13:57,810
Let's say we just assign a value my name to it.

190
00:13:57,880 --> 00:14:02,380
It means every time that we go through the signal we call it Eimear Let's see

191
00:14:07,410 --> 00:14:12,340
so whether I have something in there or not when I go it's as if you know whether I have some random

192
00:14:12,640 --> 00:14:17,290
characters in there it's still going to say the same thing but what we wanted to do is you want to get

193
00:14:17,290 --> 00:14:18,340
that information.

194
00:14:18,380 --> 00:14:25,210
And the last example what they did is I got it in here when I was pressing the button and I was passing

195
00:14:25,210 --> 00:14:28,730
it into the center for the preparation.

196
00:14:28,810 --> 00:14:30,950
Let's simplify that a little bit as well.

197
00:14:30,970 --> 00:14:34,910
Even though it's not the best practice and you will soon see why.

198
00:14:34,930 --> 00:14:36,900
But let's simplify it a little bit.

199
00:14:37,120 --> 00:14:42,480
I'm going to say when you want to go to the pink don't do any of these things and the center is now

200
00:14:42,640 --> 00:14:44,210
as it has always been.

201
00:14:44,440 --> 00:14:54,170
When you are preparing find your Pinkins stance and Pinkins stands received that may it what ever textfield

202
00:14:54,190 --> 00:14:56,650
we have dot text.

203
00:14:56,860 --> 00:15:06,640
So in the preparation set that they are all correctly and then in my pink one of said whenever this

204
00:15:06,640 --> 00:15:13,510
view Laud's get the label in its text show whatever data we have to see if that's on that again.

205
00:15:19,000 --> 00:15:25,660
So now I'm going to say here we see here I'm going to stay home.

206
00:15:25,780 --> 00:15:26,540
Vissi see.

207
00:15:26,650 --> 00:15:31,510
So that data is getting passed correctly between the two controllers.

208
00:15:32,050 --> 00:15:38,240
So that's about that there isn't a lot of coding yet on most of it is kind of you know trivial.

209
00:15:38,270 --> 00:15:46,510
We have a text field we have an action in our data and we have it perform say that we have seen and

210
00:15:46,510 --> 00:15:49,390
then you know you are paying through a controller.

211
00:15:49,390 --> 00:15:53,350
We have a property we have a label and we have a go by code.

212
00:15:53,500 --> 00:15:58,590
The only thing that's really new when you're is this little part preparing for a segue.

213
00:15:58,730 --> 00:16:04,150
And when you prepare for a sick day you get the destination viewpoint to read that you have your assignment

214
00:16:04,170 --> 00:16:10,710
to one instance of the same type person that understands you essentially call whatever you have to call.

215
00:16:10,720 --> 00:16:17,200
In this case being received data in one of the assignments that you guys have to do is to see if data

216
00:16:17,200 --> 00:16:19,410
is actually not an unnecessary thing.

217
00:16:19,480 --> 00:16:20,730
It's actually an array.

218
00:16:20,740 --> 00:16:25,740
So you have to feed an array into it in your prepare for a break.

219
00:16:25,750 --> 00:16:27,580
So let's keep it up to here.

220
00:16:27,760 --> 00:16:33,490
Like I said before this for lessons this one was the fourth one of them are quite important and you

221
00:16:33,490 --> 00:16:38,230
will have to deal with this on and on and on throughout whatever development you do.

222
00:16:38,260 --> 00:16:44,020
So if you know if you have any questions let me know if you other doubts let me try to clear them for

223
00:16:44,020 --> 00:16:46,870
you and see you in the next lesson.
