1
00:00:04,430 --> 00:00:05,660
Everyone welcome back.

2
00:00:05,660 --> 00:00:11,690
Joining me here with slopestyle and we are still working on our shortcut app in this Target topic.

3
00:00:11,690 --> 00:00:11,980
All right.

4
00:00:11,990 --> 00:00:13,360
Pretty exciting stuff so far.

5
00:00:13,360 --> 00:00:20,570
We are able to click on our app and get these nifty shortcut quick actions to pop up.

6
00:00:20,600 --> 00:00:24,490
But when we click on them they're not doing what we want them to do are they.

7
00:00:24,500 --> 00:00:26,100
So go ahead and work on that.

8
00:00:26,450 --> 00:00:31,910
So the quick actions they are actually handled in the app delegate file.

9
00:00:32,060 --> 00:00:32,350
Right.

10
00:00:32,360 --> 00:00:37,500
And so we can actually get rid of get rid of most of these.

11
00:00:38,540 --> 00:00:46,400
And the function that we want is called perform action for short cut items so you just start typing

12
00:00:46,400 --> 00:00:49,790
perform action shortcut.

13
00:00:50,210 --> 00:00:53,870
You should get the auto completion right here.

14
00:00:53,870 --> 00:00:54,380
OK.

15
00:00:54,740 --> 00:00:57,650
So let's take a look at this function we are passed into it.

16
00:00:57,650 --> 00:01:05,280
Application the shortcut item which is of type application shortcut item and a completion handler.

17
00:01:05,540 --> 00:01:13,310
All right so we are expected to actually call the completion handler and pass it a boolean true or false.

18
00:01:13,310 --> 00:01:21,830
All right so but just for starters just go ahead and just print out say print and print out the short

19
00:01:22,310 --> 00:01:23,300
cut item.

20
00:01:23,380 --> 00:01:28,850
If you remember what are the keys and the properties of shortcut item we are able to do the types.

21
00:01:28,850 --> 00:01:30,720
Let's print out the type here.

22
00:01:31,070 --> 00:01:38,530
All right we're going to run this and this should print out the item type when we click on it.

23
00:01:38,680 --> 00:01:39,000
OK.

24
00:01:39,040 --> 00:01:50,870
So bring up the simulator here and go home and oh I should tell you that if so what I'm using here I'm

25
00:01:50,870 --> 00:01:59,990
forced touching with my Magic Trackpad nifty thing here you might find it difficult to do this unless

26
00:01:59,990 --> 00:02:06,060
you have a newer either a MacBook Pro or you have this trackpad.

27
00:02:06,380 --> 00:02:12,030
So you might need to run it on your device to be able to to really test this out all right.

28
00:02:12,500 --> 00:02:19,250
But anyways I'm going to cook here on the mountains and I should have pulled it over here sure enough.

29
00:02:19,250 --> 00:02:19,930
Here we go.

30
00:02:19,930 --> 00:02:23,410
Come out Johnny B does short cut that mountains.

31
00:02:23,420 --> 00:02:30,860
All right so this is the bundle Id dropped and then our whole thing is our type but we got our bundle

32
00:02:30,860 --> 00:02:37,600
I.D. and then dot mountains and if we click on the other one let's see here.

33
00:02:38,280 --> 00:02:41,050
That was regular quick force touch.

34
00:02:41,300 --> 00:02:47,870
We have space printed out and forced touch and ocean.

35
00:02:47,900 --> 00:02:49,500
Have it go all right.

36
00:02:49,520 --> 00:02:51,050
So pretty cool.

37
00:02:51,080 --> 00:02:52,580
So we know that's working.

38
00:02:52,940 --> 00:02:59,350
So we're going to need some way of determining which one that we are clicking on and what to do something

39
00:02:59,360 --> 00:02:59,900
where you're in it.

40
00:02:59,900 --> 00:03:01,390
We're going to need an enumerator here.

41
00:03:01,400 --> 00:03:07,340
That would be helpful for any use in the numerator to be able to use a switch statement and just have

42
00:03:07,430 --> 00:03:11,260
different cases and handle them on a case by case basis.

43
00:03:11,390 --> 00:03:19,460
All right so we're going to say enough and we're going to name this short cut type probably don't need

44
00:03:19,460 --> 00:03:21,500
a capital C to shortcut type.

45
00:03:21,500 --> 00:03:22,230
There we go.

46
00:03:22,700 --> 00:03:24,940
And our first cases.

47
00:03:24,950 --> 00:03:29,880
Oh this is going to be of type String we're going to have raw values of string.

48
00:03:30,080 --> 00:03:30,430
OK.

49
00:03:30,510 --> 00:03:31,990
We went to a mountain

50
00:03:34,550 --> 00:03:38,660
and then there should be an equal equal to

51
00:03:42,080 --> 00:03:45,540
mountains.

52
00:03:45,910 --> 00:03:51,570
And so these are going to be exactly need to accidentally match what we have in our infant up here just

53
00:03:51,820 --> 00:03:54,630
at the end of our shortcut.

54
00:03:54,640 --> 00:04:02,220
Item type Ok so Mountains space lower lowercase and ocean.

55
00:04:02,230 --> 00:04:02,830
OK.

56
00:04:03,460 --> 00:04:13,290
So we have mountains and then we have case is space and that equal to space.

57
00:04:13,900 --> 00:04:19,600
And let's we have the ocean ocean to ocean.

58
00:04:19,970 --> 00:04:25,650
All right on the scene is just so that we don't have a bunch of magic strings floating around.

59
00:04:25,660 --> 00:04:25,900
All right.

60
00:04:25,900 --> 00:04:29,260
So I just kind of make it a little bit more safe.

61
00:04:29,260 --> 00:04:36,190
All right so now what we're going to do is we are going to use our shortcut right here and we're going

62
00:04:36,190 --> 00:04:39,120
to extract the type from it.

63
00:04:39,310 --> 00:04:48,470
So we're going to do it we're going to say if that type is equal to short cut item which is passed into

64
00:04:48,490 --> 00:04:51,900
us this is the short cut item of whichever one that we click on.

65
00:04:52,420 --> 00:04:59,230
And what we're going to do is we are going to say we're going to access the type and so this right here

66
00:04:59,380 --> 00:05:01,900
is going to be what we have here.

67
00:05:01,900 --> 00:05:02,450
All right.

68
00:05:02,710 --> 00:05:09,960
And what we're going to do is we're going to divide it up by components split up by the period.

69
00:05:10,120 --> 00:05:10,570
OK.

70
00:05:10,750 --> 00:05:14,970
So it divided up into an array of string components.

71
00:05:15,040 --> 00:05:16,440
So it's going to be calm.

72
00:05:16,480 --> 00:05:17,260
JOHNNY B.

73
00:05:17,290 --> 00:05:25,000
Short cut and mountains and then we're just going to get the last one which is this values mountains

74
00:05:25,060 --> 00:05:27,130
or space or ocean.

75
00:05:27,460 --> 00:05:31,700
And that's how we're going to be able to do a switch statement on our short cut type right here.

76
00:05:31,720 --> 00:05:39,790
The same numerator I guess we're going to say short item type dot and then we're going to say components

77
00:05:41,230 --> 00:05:43,590
right here separated by character set.

78
00:05:43,620 --> 00:05:50,670
And as you can see that it will return a an array of strings can and will we want to divide it by or

79
00:05:50,670 --> 00:05:59,260
separate it by is of course a period and then we're going to grab the last one of it because that's

80
00:05:59,260 --> 00:05:59,940
the one that we want.

81
00:05:59,940 --> 00:06:02,170
Mountain space and ocean.

82
00:06:02,170 --> 00:06:04,360
All right so we're going to grab that if let it.

83
00:06:04,390 --> 00:06:11,710
So we have it safely unwrapped and now we can do a switch statement on that type so we can see a switch

84
00:06:13,240 --> 00:06:30,550
on the type and we can say case short cut type dot mountains that are all value and just for now we're

85
00:06:30,550 --> 00:06:41,970
going to say print these are out this then for the second case we're going to say case short cut type

86
00:06:42,160 --> 00:06:43,340
dot.

87
00:06:43,690 --> 00:06:52,090
Let's see what was on Space space that raw value and we're going to save print.

88
00:06:52,090 --> 00:06:54,430
This is space.

89
00:06:54,430 --> 00:07:02,020
And last week we have our third case which is actually no colon here yet.

90
00:07:02,020 --> 00:07:12,060
Short cut type that ocean that raw value and we're going to see here print.

91
00:07:12,130 --> 00:07:14,290
Love the beach.

92
00:07:16,980 --> 00:07:19,700
And actually it's going to say which must be exhaustive.

93
00:07:19,880 --> 00:07:21,160
So we need a default.

94
00:07:21,250 --> 00:07:24,980
So let's go ahead and make our first Visi the default.

95
00:07:25,050 --> 00:07:30,220
And if you click on here it's going to ask us if we want to add a default clause I say sure and fix

96
00:07:30,220 --> 00:07:30,770
that.

97
00:07:31,060 --> 00:07:37,000
And what we're going to do is we're just going to take this line right here and paste it right here

98
00:07:37,000 --> 00:07:42,070
because we're going to make and we can just delete the Surekha typed on mountains that Rob you will

99
00:07:42,070 --> 00:07:49,150
make the first Visi be the default the case that Google is going to do a little bit of clean up here.

100
00:07:49,150 --> 00:07:51,090
All right let's go ahead and try that again.

101
00:07:51,100 --> 00:07:51,840
Going to run it.

102
00:07:52,210 --> 00:07:58,060
And just to recap while we're coming up here we created an enumerator called shortcut type with three

103
00:07:58,060 --> 00:08:00,270
cases mountain space and ocean.

104
00:08:00,280 --> 00:08:08,440
Each of its raw values corresponds exactly to the value that we entered here and the input up the list

105
00:08:08,440 --> 00:08:13,450
right here and come back here and then we have a switch statement.

106
00:08:13,450 --> 00:08:23,770
Well first we are extracting from our shortcut item when we click we are grabbing out of the full string

107
00:08:24,160 --> 00:08:26,950
including our bundle identifier and just getting that last value.

108
00:08:27,130 --> 00:08:34,440
And then we're doing a switch statement and we will handle the shortcut actions on a case by case basis.

109
00:08:34,480 --> 00:08:42,040
So we couldn't test this and click here and force touch and when it's like the mountains and we are

110
00:08:42,040 --> 00:08:48,990
printing these other mountains that's good and a force for touch again and say space is space.

111
00:08:49,180 --> 00:08:53,160
And lastly love the beach.

112
00:08:53,350 --> 00:08:54,500
All right perfect.

113
00:08:54,520 --> 00:09:00,210
So now we are actually handling each individual quick action.

114
00:09:00,340 --> 00:09:06,240
So just think about what we want to have happen when we click on the shortcut items.

115
00:09:06,280 --> 00:09:14,340
So when we click on this ocean for example we want to go directly to the ocean view.

116
00:09:14,350 --> 00:09:14,840
All right.

117
00:09:15,070 --> 00:09:21,940
But what if we have launched it for the first time and if we launch it for the first time and we open

118
00:09:21,940 --> 00:09:22,280
it.

119
00:09:22,420 --> 00:09:27,690
The only view that has loaded that's been instantiated is this first one right.

120
00:09:27,850 --> 00:09:31,930
And if you check now I mean that scoreboard storyboard we have three controllers.

121
00:09:32,020 --> 00:09:37,450
So if we launched the first time only this one has been instantiated so we can't just say you know Segway

122
00:09:37,450 --> 00:09:40,540
directly over here to this third one.

123
00:09:40,540 --> 00:09:47,020
So what we're going to do is rush to go into on did finish launching with options so once we have finished

124
00:09:47,020 --> 00:09:56,050
launching we're actually just going to instantiate all three and store them in a controller array because

125
00:09:56,290 --> 00:10:02,860
one nice thing about the one we have are all of our views embedded in a navigation controller is that

126
00:10:02,860 --> 00:10:09,880
we can use some of the nice methods that it has and just pop to different view controllers as long as

127
00:10:10,150 --> 00:10:18,730
the view controls are part of the stack and we can add any we can add an array of controllers to a navigation

128
00:10:18,730 --> 00:10:19,830
controller stack.

129
00:10:19,900 --> 00:10:20,390
OK.

130
00:10:20,530 --> 00:10:26,680
So we're going to instantiate our three view controllers and put them inside of an array and then we

131
00:10:26,680 --> 00:10:34,130
are going to add that array of controllers to the route controller and navigation stack.

132
00:10:34,440 --> 00:10:42,840
So out here under our window a variable is going create a variable for that someone to say VCs array.

133
00:10:43,060 --> 00:10:50,470
I'm going to instantiate this right here so it's going to be an array of UI view controller and instantiate

134
00:10:50,470 --> 00:10:51,110
that.

135
00:10:51,580 --> 00:10:56,430
And then here and finish launching with options we're going to need a reference to our storyboards.

136
00:10:56,440 --> 00:11:12,790
When I say let storyboard equal to you I story that's how you story board and its name is main as you

137
00:11:12,790 --> 00:11:17,630
can see right here main storyboard and the bundle we can just put in.

138
00:11:17,990 --> 00:11:18,870
OK there we go.

139
00:11:18,970 --> 00:11:24,410
So now we have a reference for storyboard we can instantiate a view controller from it and say let And

140
00:11:24,410 --> 00:11:33,650
it is going to be mountain VCM is equal to storyboard that instantiate controller.

141
00:11:33,970 --> 00:11:38,370
And this is why we had our identifiers here.

142
00:11:39,160 --> 00:11:46,230
If you remember we added mountains we see here our storyboard ID mountains Visi kit.

143
00:11:46,270 --> 00:11:48,910
And so when you get to delegate and our identifier here

144
00:11:52,060 --> 00:12:02,360
is my own patterns we see that we go and we're going to cast it as a mountains of visi.

145
00:12:02,780 --> 00:12:04,270
All right then we're gonna do that for our other two.

146
00:12:04,270 --> 00:12:13,650
When I say let the space seem to storyboard it instantiate the view controller with identifier.

147
00:12:13,740 --> 00:12:24,630
And this one's identifier is space Visi And we cast it as a space receive controller and clothes a left

148
00:12:24,630 --> 00:12:27,510
pane here and give us a little bit more space.

149
00:12:27,620 --> 00:12:29,640
OK need our exclamation point there.

150
00:12:30,070 --> 00:12:38,790
Right I'm going to say that ocean we see equal storyboard dot instantiated controller with identifier

151
00:12:39,150 --> 00:12:42,630
and the identifier is of course ocean.

152
00:12:43,170 --> 00:12:47,440
And we are casting it as an ocean.

153
00:12:47,640 --> 00:12:48,560
There you go.

154
00:12:48,810 --> 00:12:52,040
So now we have our three controllers instantiated.

155
00:12:52,230 --> 00:12:55,380
And now let's go ahead and add them to our A B C's array.

156
00:12:55,530 --> 00:12:59,060
So I want to say VCs array is equal to.

157
00:12:59,280 --> 00:13:05,530
And then I'm just going to put them in right here from the same mountain VCAT space.

158
00:13:05,670 --> 00:13:08,820
Space Fisi and ocean.

159
00:13:08,870 --> 00:13:10,660
We see that.

160
00:13:10,890 --> 00:13:17,170
So now we have our array of view controllers so we can actually use them down here in our perform action.

161
00:13:17,520 --> 00:13:25,040
So when we click on the our own we tap on the space for an item we want to navigate to the space one.

162
00:13:25,260 --> 00:13:29,160
So what we're going to need to do is we're going to need to get access to our route.

163
00:13:29,350 --> 00:13:32,040
Controller came and how we're going to do that.

164
00:13:32,060 --> 00:13:41,890
And we are going to say let nav Visi and we're going to use the window right here to get to it.

165
00:13:41,910 --> 00:13:51,450
We're going to see that and have the sea equal window dot route view controller and we're going to cast

166
00:13:51,450 --> 00:13:56,400
that has a UI navigation controller.

167
00:13:56,570 --> 00:13:57,040
OK.

168
00:13:57,180 --> 00:14:04,840
And so what we're doing is we're saying we're saying this guy is and let me open up my main storyboard

169
00:14:04,840 --> 00:14:07,340
board is this guy right here.

170
00:14:07,350 --> 00:14:10,550
This is what we are calling Nav. the sea.

171
00:14:10,740 --> 00:14:11,320
OK.

172
00:14:11,610 --> 00:14:20,730
So let VCP do route view controller and then we need to set its array of controllers so we can say now

173
00:14:20,760 --> 00:14:27,890
Visi that set the controllers and we are going to pass in this array of controllers that we just created.

174
00:14:28,140 --> 00:14:28,450
OK.

175
00:14:28,470 --> 00:14:30,530
So let's see here.

176
00:14:30,840 --> 00:14:35,750
This is VCs array animated false.

177
00:14:35,760 --> 00:14:36,420
There you go.

178
00:14:36,420 --> 00:14:43,800
So now our navigation controller has a full stack of controllers that we can navigate to.

179
00:14:43,800 --> 00:14:49,440
All right so now that we have instantiated them added them now we can tell it to pop to any of those

180
00:14:49,650 --> 00:14:55,470
controllers at any point and it will maintain the order that we would expect if we pop to the third

181
00:14:55,470 --> 00:15:00,220
one then we can go back and we'll back through to the second and then to the first.

182
00:15:00,330 --> 00:15:04,800
If we take if we pop to the second one we just pop to the second one and we can continue on to the third

183
00:15:04,800 --> 00:15:06,250
one or go back to the first one.

184
00:15:06,300 --> 00:15:07,460
All right it's going to be pretty cool.

185
00:15:11,050 --> 00:15:17,320
So here where we shortcut to space let's go and remove this print statement and what we're going to

186
00:15:17,320 --> 00:15:23,710
do is we're going to say now have these dot pop to view controller and you can see all these options

187
00:15:23,710 --> 00:15:28,530
you can pop to your controller and that will just go directly to a specific controller.

188
00:15:28,600 --> 00:15:35,650
If you say pop the controller then it removes the top few controller from the stack and goes to the

189
00:15:35,650 --> 00:15:36,690
one below it.

190
00:15:36,870 --> 00:15:39,050
You can pop to the root view controller.

191
00:15:39,100 --> 00:15:44,350
So no matter where you are in the navigation stack if you call this one then you go right back all the

192
00:15:44,350 --> 00:15:48,710
way to the beginner all the way to the beginner route you control.

193
00:15:48,980 --> 00:15:52,150
And so we want to be a controller.

194
00:15:52,480 --> 00:15:59,620
And for the for this one so this is going to the second view controller space visi.

195
00:15:59,800 --> 00:16:00,910
So in this array.

196
00:16:01,060 --> 00:16:02,500
This is the.

197
00:16:02,650 --> 00:16:05,650
So you go 0 then 1 and then 2.

198
00:16:05,890 --> 00:16:09,100
So this is the one item in the array.

199
00:16:09,330 --> 00:16:19,670
So right here we're going to say on the C's array and the one item animated is true.

200
00:16:20,200 --> 00:16:27,190
And then remember at this function perform action for for the item expects us to call the completion

201
00:16:27,190 --> 00:16:30,460
handler and pass in a true or a false.

202
00:16:30,460 --> 00:16:33,560
So here we have we've been successful.

203
00:16:33,700 --> 00:16:39,850
So we're going to see completion Hendler and true that we go.

204
00:16:40,030 --> 00:16:48,840
And then if we click on the ocean one we want to pop to the ocean Vcc and say nav we see that pop to

205
00:16:48,850 --> 00:16:49,700
your controller.

206
00:16:49,810 --> 00:16:52,890
If we control that we want to pop to VCs VCs array.

207
00:16:53,050 --> 00:16:57,730
And this is the second item or the 0 1 tooth item.

208
00:16:57,830 --> 00:16:59,860
And I mean it is true.

209
00:17:00,360 --> 00:17:05,850
Kim and default is the first controller.

210
00:17:06,160 --> 00:17:13,570
And so what we can do here is we can say never VC that pop to route controller since is the default

211
00:17:13,570 --> 00:17:16,900
that we want to get back to the first controller.

212
00:17:16,910 --> 00:17:26,870
We're just going to pop to the route and say animated is true and completion handler is true.

213
00:17:26,910 --> 00:17:31,940
Looks There we go.

214
00:17:31,980 --> 00:17:32,210
All right.

215
00:17:32,210 --> 00:17:32,940
Perfect.

216
00:17:33,240 --> 00:17:41,540
And then if we weren't able to get a short cut item so if this failed then we're going to say completion

217
00:17:41,550 --> 00:17:46,150
handler and false.

218
00:17:46,210 --> 00:17:46,420
All right.

219
00:17:46,420 --> 00:17:50,180
So let's save this and run it and let's see if this works.

220
00:17:50,510 --> 00:17:52,790
Whoops we got a little bit of an error here.

221
00:17:52,790 --> 00:17:54,320
That's what we did wrong.

222
00:17:55,440 --> 00:17:55,650
Oh.

223
00:17:55,680 --> 00:18:04,280
You know what I did we forgot or I forgot to set the controller classes for these other two control

224
00:18:04,280 --> 00:18:05,130
issue.

225
00:18:05,130 --> 00:18:14,340
So with the second one selected here you controller this should be set to space Visi and the third one

226
00:18:14,940 --> 00:18:19,810
should be set to oceanview see an area.

227
00:18:20,040 --> 00:18:21,880
Let's try that again.

228
00:18:21,900 --> 00:18:24,110
All right I'm going to go home.

229
00:18:24,410 --> 00:18:25,880
Force touch.

230
00:18:26,070 --> 00:18:28,820
And let's pick ocean and we should.

231
00:18:28,880 --> 00:18:30,060
We're very nice.

232
00:18:30,060 --> 00:18:38,280
We went directly to the ocean view and let's do that again let's go to space and go to space and you

233
00:18:38,280 --> 00:18:42,780
can see that we can still navigate just like normal.

234
00:18:42,860 --> 00:18:49,830
Let's go to all the way to the third one directly and then try to navigate back and that is all normal

235
00:18:49,830 --> 00:18:51,060
as well.

236
00:18:51,060 --> 00:18:51,520
All right.

237
00:18:51,540 --> 00:18:52,890
Very nice.

238
00:18:52,890 --> 00:18:53,880
So there you have it.

239
00:18:53,880 --> 00:19:01,980
We are officially using quick actions to navigate directly to different view controllers in your app.

240
00:19:02,010 --> 00:19:03,660
So that is pretty cool.

241
00:19:03,660 --> 00:19:03,860
All right.

242
00:19:03,900 --> 00:19:05,670
So there you have it.

243
00:19:05,730 --> 00:19:07,750
Our app is pretty much complete now.

244
00:19:08,010 --> 00:19:09,570
So we're going to do a little bit more.

245
00:19:09,570 --> 00:19:13,470
We're going to see how this works with tab controllers.

246
00:19:13,470 --> 00:19:13,910
All right.

247
00:19:14,100 --> 00:19:18,140
So we're going to do a little bit more show you a little bit more tricks and I'll see you then.
