1
00:00:07,900 --> 00:00:11,140
Hey everybody what's going on this is Caleb with slopes dot com.

2
00:00:11,160 --> 00:00:14,420
And in this video we're going to download that additional data that we need.

3
00:00:14,550 --> 00:00:20,400
The contributor's data as well as the avatar image and we're also going to set up some conditional safety

4
00:00:20,400 --> 00:00:25,700
checks to make sure that all the repositories that we are downloading have all the properties we need.

5
00:00:25,710 --> 00:00:30,570
If you remember in the last video we got a crash because one of the Repos did not have an avatar you

6
00:00:30,570 --> 00:00:35,340
or else so we're going to set it up so that when we download that data we're only going to get data

7
00:00:35,340 --> 00:00:39,870
that has all the properties we need and we can actually checked against that using guard Blatt which

8
00:00:39,870 --> 00:00:41,550
is really really really cool.

9
00:00:41,610 --> 00:00:46,520
So go ahead and pull open your X code project just like so and we're going to do that.

10
00:00:46,530 --> 00:00:49,800
Now we're going to make sure that everything is coming in the way we want.

11
00:00:49,800 --> 00:00:50,390
OK.

12
00:00:50,610 --> 00:00:58,470
So inside your trending repots dict array function we're going to go into the for loop here and we're

13
00:00:58,470 --> 00:01:03,040
going to go inside our if trending repots array count is less than or equal to 9.

14
00:01:03,390 --> 00:01:09,260
And this is where we're going to use guard let to ensure that every repo has the values we need.

15
00:01:09,420 --> 00:01:11,670
And we're going to use guard guard led to do that.

16
00:01:11,670 --> 00:01:18,370
So go ahead and type guard let And we're going to create an individual property for all of these.

17
00:01:18,360 --> 00:01:21,010
Remember these are all of the properties that we want.

18
00:01:21,030 --> 00:01:25,980
So I'm actually going to go ahead and unstick this because after we fix this we will no longer have

19
00:01:25,980 --> 00:01:28,000
a problem with these values coming in.

20
00:01:28,260 --> 00:01:30,040
So go ahead and copy this.

21
00:01:30,080 --> 00:01:33,840
OK we're going to use it up here and you're probably saying oh that's copying and pasting.

22
00:01:34,020 --> 00:01:34,880
Yeah that's true.

23
00:01:35,040 --> 00:01:42,420
But down here we're basically casting them as values in swift and then we're using them to create an

24
00:01:42,420 --> 00:01:44,400
instance of repo so it's different.

25
00:01:44,400 --> 00:01:52,560
But now what we can do is we can color guard let And the cool thing with a guard that is we can use

26
00:01:52,650 --> 00:01:57,180
a string and not a string but a we can use.

27
00:01:57,300 --> 00:01:57,570
OK.

28
00:01:57,660 --> 00:02:04,440
A long list of properties and we can put them into the same guard let so that we make sure that all

29
00:02:04,440 --> 00:02:05,930
of the values come back.

30
00:02:05,940 --> 00:02:08,060
Otherwise we're just going to return.

31
00:02:08,070 --> 00:02:11,790
So it's basically going to allow us to go through fill all the values.

32
00:02:11,820 --> 00:02:15,730
If there's a value for all of it it will create all of them if one is missing.

33
00:02:15,750 --> 00:02:18,480
It doesn't create any of them so it's a really cool safety check.

34
00:02:18,690 --> 00:02:24,690
But we need to basically put commas between them and that will help us to separate them.

35
00:02:24,960 --> 00:02:27,730
And let's do that now so we're going to go ahead.

36
00:02:27,790 --> 00:02:30,210
Last there for string.

37
00:02:30,240 --> 00:02:35,600
Let's go ahead and put a comma and a space and one more comment in a space.

38
00:02:35,610 --> 00:02:35,900
OK.

39
00:02:35,910 --> 00:02:36,630
Very cool.

40
00:02:36,630 --> 00:02:42,300
And after each comma we can actually go in and return these down.

41
00:02:42,310 --> 00:02:44,270
So it looks a little prettier.

42
00:02:44,790 --> 00:02:46,740
Right before the let.

43
00:02:47,190 --> 00:02:47,590
OK.

44
00:02:47,610 --> 00:02:48,840
Very cool.

45
00:02:48,840 --> 00:02:58,190
So it looks like we're getting avatar you are l a name description number of fork's language repo you

46
00:02:58,200 --> 00:02:58,650
RL.

47
00:02:58,650 --> 00:03:00,490
OK we have one more that we need.

48
00:03:00,570 --> 00:03:02,070
We need that contributor's data.

49
00:03:02,070 --> 00:03:04,190
So go ahead and put a comma.

50
00:03:04,350 --> 00:03:10,400
Let contributor's you RL And that's going to be equal to the dictionary.

51
00:03:10,560 --> 00:03:14,360
But then the contributor's you are a let's go find out what the key for that is.

52
00:03:15,110 --> 00:03:15,450
All right.

53
00:03:15,470 --> 00:03:23,240
So contributor's you r l I believe is just contributor's underscore u r l Paiste that n it's going to

54
00:03:23,240 --> 00:03:25,100
be of type string.

55
00:03:25,570 --> 00:03:28,210
K then do we have any other ones.

56
00:03:28,250 --> 00:03:36,460
We have a name description language for X repo contributor's data avatar you Arel.

57
00:03:37,340 --> 00:03:41,120
Hmm let's think

58
00:03:44,190 --> 00:03:47,950
well you know what actually I do notice something here.

59
00:03:47,970 --> 00:03:53,770
The avatar you are l is not a part of the big dictionary that we're looking at.

60
00:03:53,790 --> 00:03:56,900
It's part of another dictionary inside called owner.

61
00:03:57,150 --> 00:04:02,650
So what we can do is we can basically cast owner and then pull out the avatar you are l.

62
00:04:02,730 --> 00:04:07,230
We should do that to make sure that we don't miss something so I'm actually going to remove avatar you

63
00:04:07,230 --> 00:04:14,760
are l and move this guard let name property appear then below contributor's you or else I'm going to

64
00:04:14,760 --> 00:04:16,390
go ahead and paste that.

65
00:04:16,500 --> 00:04:24,940
But we need to first cast the owner dictionary from our our function here so to do that.

66
00:04:24,990 --> 00:04:31,840
Go ahead and beneath this just call Let owner dict equals dictionary.

67
00:04:31,880 --> 00:04:33,300
Whoops sorry dict.

68
00:04:33,600 --> 00:04:35,550
And that property is called owner.

69
00:04:35,550 --> 00:04:36,200
Right.

70
00:04:36,420 --> 00:04:41,460
But we need to cast this as a dictionary of string.

71
00:04:41,970 --> 00:04:42,840
And any.

72
00:04:43,140 --> 00:04:43,770
OK.

73
00:04:44,130 --> 00:04:47,280
Oh and one other thing you notice all these errors.

74
00:04:47,730 --> 00:04:49,180
Comma there to separate them.

75
00:04:49,200 --> 00:04:53,010
You'll notice we get a ton of errors and that's because inside of a guard light you're not allowed to

76
00:04:53,010 --> 00:04:55,290
force on wrap things you need to optionally cast them.

77
00:04:55,290 --> 00:05:00,780
So we need to actually change these all to optionals because basically a guard let works under the premise

78
00:05:00,870 --> 00:05:06,360
of these values are optional meaning if there is a value we're going to move forward if there's not

79
00:05:06,360 --> 00:05:07,700
a value we're going to return.

80
00:05:07,710 --> 00:05:09,590
So we need to make them all optional.

81
00:05:09,750 --> 00:05:16,290
And it looks like it's saying use of an resolved identifier dict and I don't know why that is.

82
00:05:16,470 --> 00:05:17,900
Oh that's because it's repo dict.

83
00:05:17,910 --> 00:05:18,510
My bad.

84
00:05:18,660 --> 00:05:21,670
I missed that the whole time that's why you don't copy and paste code folks.

85
00:05:21,900 --> 00:05:26,040
OK so we're going to copy and paste it like I'm doing here sorry being a bad example.

86
00:05:26,190 --> 00:05:26,860
Anyway so.

87
00:05:26,870 --> 00:05:27,120
OK.

88
00:05:27,120 --> 00:05:27,940
Check it out.

89
00:05:27,960 --> 00:05:30,450
We now have a property for repo dict.

90
00:05:30,540 --> 00:05:37,440
We have a property for all of these but remember owner DECT is now its own dictionary and the avatar

91
00:05:37,440 --> 00:05:38,910
you are l is inside of that.

92
00:05:38,910 --> 00:05:45,250
So we need to call avatar you are ELF from owner dict like so.

93
00:05:45,260 --> 00:05:45,880
All right.

94
00:05:45,960 --> 00:05:51,630
Now the interesting thing is since these are all connected with comma's we can call it else.

95
00:05:51,630 --> 00:05:57,930
And if all of these values do not come in if we miss even a single one we are going to go ahead and

96
00:05:57,930 --> 00:05:59,080
call break.

97
00:05:59,190 --> 00:06:04,290
And that means it's going to break out of the for loop or at least break out of this section of the

98
00:06:04,290 --> 00:06:05,070
for loop.

99
00:06:05,070 --> 00:06:06,790
OK that's pretty cool.

100
00:06:06,780 --> 00:06:13,050
So now assuming we've made it through and we have a value for every single one of these We're going

101
00:06:13,050 --> 00:06:15,120
to go ahead and create a dictionary.

102
00:06:15,240 --> 00:06:15,800
OK.

103
00:06:15,930 --> 00:06:20,510
And that's the dictionary that we actually should be appending to are trending repose.

104
00:06:20,760 --> 00:06:25,700
So let's go ahead and let's create Ribault dictionary.

105
00:06:26,070 --> 00:06:26,790
OK.

106
00:06:27,090 --> 00:06:32,100
Now you know what we should set an explicit type for this so that it knows that it is a dictionary of

107
00:06:32,100 --> 00:06:33,140
type string.

108
00:06:33,300 --> 00:06:34,500
And any.

109
00:06:35,010 --> 00:06:36,830
And now let's go ahead and let's build it.

110
00:06:37,020 --> 00:06:42,340
So the first key is going to be name right.

111
00:06:42,360 --> 00:06:43,220
That's great.

112
00:06:43,440 --> 00:06:47,250
And the name is going to come from the name property that we've already set.

113
00:06:47,250 --> 00:06:50,830
Next we're going to go ahead and just call description.

114
00:06:51,810 --> 00:06:54,500
And that's going to be from description.

115
00:06:54,510 --> 00:06:57,930
Next we're going to have a number of forks.

116
00:06:57,960 --> 00:07:02,660
Whoops that needs to be a key fork's underscore count.

117
00:07:02,670 --> 00:07:07,290
I'm going to use the same ones as the repository so that we don't have any issues and that's going to

118
00:07:07,290 --> 00:07:09,830
be set to be equal to number of forks.

119
00:07:09,840 --> 00:07:14,660
Next we're going to have language.

120
00:07:14,690 --> 00:07:18,190
And that's going to come from language.

121
00:07:18,260 --> 00:07:19,160
All right what's next.

122
00:07:19,160 --> 00:07:27,020
We have a few more we have let's see to do repo you RL.

123
00:07:27,240 --> 00:07:28,470
Whoops sorry.

124
00:07:28,700 --> 00:07:36,260
That's actually HVM l u r l underscore T.M. u r l and that comes from Ribault u r l.

125
00:07:36,680 --> 00:07:45,830
Then we have contributors you are l so let's go ahead and let's cast that contributor's underscore you

126
00:07:45,830 --> 00:07:46,720
are l.

127
00:07:47,060 --> 00:07:50,670
That comes from the property contributor's you are l.

128
00:07:50,810 --> 00:07:58,250
Then we have Avatar u r l and that comes from Avatar you are l.

129
00:07:58,400 --> 00:08:03,000
All right so there our dictionary that has all the values we need right.

130
00:08:03,050 --> 00:08:08,630
We have our contributors you are l we have our name description number of fork's programming language

131
00:08:08,720 --> 00:08:14,030
Ribault you r l contributor's you are l and Avatar your L we don't need owners dictionary because we

132
00:08:14,030 --> 00:08:19,320
just need the value of Avatar you r l so that looks pretty good.

133
00:08:19,370 --> 00:08:24,620
And now we can just go ahead and pass Ribault dictionary and we can pass that back to our function and

134
00:08:24,620 --> 00:08:26,540
this should work the same exact way.

135
00:08:26,840 --> 00:08:33,350
Now when we go through here we will definitely have an avatar u r l which is pretty neat and we will

136
00:08:33,350 --> 00:08:38,570
definitely have a contributor's you r l so you know what we can actually add in a property here for

137
00:08:38,570 --> 00:08:39,010
that.

138
00:08:39,050 --> 00:08:49,010
Let's just type let contributor's u r l equals dictionary and the value coming in is contribute towards

139
00:08:49,070 --> 00:08:52,400
underscore u r l as a string.

140
00:08:52,400 --> 00:08:56,070
Of course because it will be coming in as non-optional.

141
00:08:56,240 --> 00:09:01,940
And now we are good to go we can use these two to download the image and download the contributor's

142
00:09:01,940 --> 00:09:02,720
data.

143
00:09:02,720 --> 00:09:04,670
So let's go write those functions now.

144
00:09:04,820 --> 00:09:07,910
So go ahead and write above.

145
00:09:07,950 --> 00:09:09,090
Let's see.

146
00:09:09,530 --> 00:09:11,510
Well why don't we do this down at the bottom.

147
00:09:11,510 --> 00:09:18,220
We're going to go ahead and go below here and I'm going to type phunk download image for and it's going

148
00:09:18,220 --> 00:09:23,360
to be for a specific avatar you are l of type string.

149
00:09:23,390 --> 00:09:25,940
String string.

150
00:09:25,940 --> 00:09:26,570
There we go.

151
00:09:26,780 --> 00:09:32,600
And since it's really dependent since the order is very important we're going to use a completion handler

152
00:09:32,840 --> 00:09:37,850
so that each repository cannot move on until the function is finished in a very particular way.

153
00:09:37,910 --> 00:09:43,400
So go ahead and cut type completion and it's going to be escaping so we can pass the image back to where

154
00:09:43,400 --> 00:09:49,460
we want then we're going to create a function that returns an empty function and inside of this we're

155
00:09:49,460 --> 00:09:54,920
going to return an image and that's going to be wups of type II image.

156
00:09:55,240 --> 00:09:56,450
OK that's pretty cool.

157
00:09:56,750 --> 00:09:58,250
So give it some curly brackets.

158
00:09:58,250 --> 00:10:04,100
And now what we're going to do is we're going to use Alamo fire to pass in the avatar you Arel and return

159
00:10:04,100 --> 00:10:04,570
an image.

160
00:10:04,580 --> 00:10:06,790
So go ahead and call Alamo fire.

161
00:10:07,010 --> 00:10:10,250
Request and pass in the avatar you are l k.

162
00:10:10,250 --> 00:10:11,450
That's easy.

163
00:10:11,450 --> 00:10:14,730
Next we're going to go ahead and call daat response.

164
00:10:14,780 --> 00:10:21,820
Whoops can't type response response and you'll notice there is no particular way to return an image.

165
00:10:22,040 --> 00:10:25,440
But that is where Alamo fire image comes in.

166
00:10:25,490 --> 00:10:28,790
So go ahead and import that Alamo fire image.

167
00:10:28,790 --> 00:10:29,750
Very cool.

168
00:10:29,960 --> 00:10:32,690
And now watch what happens when we call response.

169
00:10:32,690 --> 00:10:34,850
You'll notice there is daat response.

170
00:10:34,850 --> 00:10:38,920
Image K and that that's going to return an image for us which is very cool.

171
00:10:38,960 --> 00:10:45,560
So on the completion händler go ahead and press enter and the image response is going to be of type.

172
00:10:45,560 --> 00:10:48,490
Data response so go ahead and type image's response.

173
00:10:48,620 --> 00:10:53,660
K and we're going to pull out the value inside that data response of type image.

174
00:10:53,690 --> 00:10:59,940
So for the image just in case we're going to be safe and use a guard lead and call image.

175
00:11:00,140 --> 00:11:04,560
We're going to set it to be equal to image response and watch what happens when I type a dot.

176
00:11:04,700 --> 00:11:10,400
We can pull out the result right here which you'll see the result casts an image inside.

177
00:11:10,400 --> 00:11:14,480
So to pull out the value is to pull out an image.

178
00:11:14,480 --> 00:11:17,340
Very cool so that's great.

179
00:11:17,510 --> 00:11:20,910
But this is a guard so we need to say if there is not an image.

180
00:11:20,960 --> 00:11:22,910
We're going to just return k.

181
00:11:23,210 --> 00:11:28,380
We don't want anything to happen or for us to have a crash so it can return nil which is really cool.

182
00:11:28,700 --> 00:11:33,680
So then what we're going to do is we're going to call our completion handler once it's downloaded we

183
00:11:33,680 --> 00:11:41,250
can pass the image like so to our completion handler and now it's done very cool.

184
00:11:41,390 --> 00:11:45,860
So this function will download an image for us from our avatar you are l.

185
00:11:46,060 --> 00:11:50,990
Next we need to get our contributors data and we're going to do this in a very similar way.

186
00:11:51,050 --> 00:12:01,790
We're going to call phunk download contribute tips and tribute Tyers data for contributors.

187
00:12:01,820 --> 00:12:03,590
You are l of type string.

188
00:12:03,770 --> 00:12:12,740
And for this we're also going to call a completion handler of type escaping and we're going to return

189
00:12:12,740 --> 00:12:14,300
an empty function.

190
00:12:14,300 --> 00:12:19,810
We're going to basically need a count of contributors so we're just going to use an underscore there

191
00:12:19,810 --> 00:12:26,510
since we're not allowed to use named types and we're going to just say contributors of type int.

192
00:12:26,530 --> 00:12:28,820
Right because that comes in as an integer value.

193
00:12:29,260 --> 00:12:30,120
So.

194
00:12:30,460 --> 00:12:32,520
Great let's think what do we need.

195
00:12:32,560 --> 00:12:37,720
We have a few RL contributors you know we need some curly brackets of course.

196
00:12:37,740 --> 00:12:43,120
OK so now let's use Alamo fire to basically pass in that you r l and see what happens.

197
00:12:43,120 --> 00:12:43,940
So go ahead and type.

198
00:12:43,930 --> 00:12:49,130
Alamo fire dot request wups Riku.

199
00:12:49,480 --> 00:12:52,100
And pass in contributor's you are l.

200
00:12:52,150 --> 00:12:59,170
Now we have not yet seen what happens when we call it contributor's you r l so let's be smart let's

201
00:12:59,170 --> 00:13:02,290
go find that u r l right here.

202
00:13:02,320 --> 00:13:04,140
And let's go ahead and paste pasted in.

203
00:13:04,140 --> 00:13:04,940
And let's check it out.

204
00:13:04,930 --> 00:13:05,840
So yeah.

205
00:13:05,860 --> 00:13:11,710
When we load it up you can see this is the list of all of the contributors by username that have contributed

206
00:13:11,710 --> 00:13:14,030
to swift which is pretty cool.

207
00:13:14,050 --> 00:13:15,010
You can see them all here.

208
00:13:15,010 --> 00:13:22,360
But as you can see they come in as well as an array of dictionaries so we can basically count the amount

209
00:13:22,360 --> 00:13:24,970
of dictionaries and that'll tell us the amount of contributors.

210
00:13:24,970 --> 00:13:27,520
There are two swift which is pretty cool.

211
00:13:27,520 --> 00:13:29,930
So we know that we can just call the count.

212
00:13:29,950 --> 00:13:34,120
But the cool thing is we know now that it is an array of dictionaries.

213
00:13:34,240 --> 00:13:36,390
That's going to help us avoid crashes.

214
00:13:36,430 --> 00:13:42,490
So let's go ahead and let's call Alamo Firedrake quest and we're going to get the response in Jaison

215
00:13:42,520 --> 00:13:44,110
just like you might have expected.

216
00:13:44,170 --> 00:13:48,550
And let's go ahead and press enter on the completion handler and call this the response which is the

217
00:13:48,550 --> 00:13:50,430
Jaison response.

218
00:13:50,740 --> 00:13:57,880
Let's be safe and let's use guard let Jaison and just like before we're going to use response.

219
00:13:57,910 --> 00:13:59,960
Got results.

220
00:14:00,550 --> 00:14:02,590
Results don't value.

221
00:14:02,800 --> 00:14:09,760
And we're going to cast that just like we saw as an array of dictionaries and we don't know always.

222
00:14:09,760 --> 00:14:14,530
We know all the keys are strings but we do not know that the type will not be any.

223
00:14:14,530 --> 00:14:20,680
So we're going to be safe and just say string and any otherwise we're going to just go ahead and return

224
00:14:20,890 --> 00:14:23,670
nothing perfect and we'll just quit out.

225
00:14:23,680 --> 00:14:28,910
But we should get some day sun and let's just make sure that there is.

226
00:14:28,930 --> 00:14:32,940
I mean just because there's a contributor's you are l doesn't always mean that there are contributors.

227
00:14:33,070 --> 00:14:38,750
So if our Jason that comes in we can call Dohm is empty.

228
00:14:38,900 --> 00:14:39,530
OK.

229
00:14:39,730 --> 00:14:45,400
And if it's empty then we're going to go ahead and do nothing but we're going to do the opposite.

230
00:14:45,400 --> 00:14:51,130
So if the opposite of Jason is empty meaning if there is Jaison what we're going to do is we're going

231
00:14:51,130 --> 00:15:01,960
to go ahead and just create a contributions value and just basically say let contributions equal Jason

232
00:15:02,290 --> 00:15:03,600
count.

233
00:15:03,610 --> 00:15:08,020
All right so that's going to be the amount of items in the dictionary will tell us how many contributors

234
00:15:08,440 --> 00:15:16,030
then we can call our completion and pass in contributors or can contributions I guess.

235
00:15:16,120 --> 00:15:22,390
So now that function is finished now we need to string them together and set it up so that we can properly

236
00:15:22,420 --> 00:15:24,280
create these repositories that we need.

237
00:15:24,280 --> 00:15:28,690
So let's go ahead and head back up to our trending repo function.

238
00:15:28,840 --> 00:15:29,710
And here we go.

239
00:15:29,710 --> 00:15:35,770
So when we create this repository we're passing it in a temporary image and a temporary contributor's

240
00:15:35,770 --> 00:15:38,460
you r l so we need to call it beforehand.

241
00:15:38,530 --> 00:15:45,940
So let's go ahead and call download image for Avatar you Aurel pass in the avatar you are ill and upon

242
00:15:45,940 --> 00:15:49,230
completion we have a returned image.

243
00:15:49,240 --> 00:15:54,860
OK then we're going to go ahead and call our download contributor's data.

244
00:15:54,880 --> 00:16:00,170
But now that we're inside a closure we need to call self download contributor's data for contributors.

245
00:16:00,190 --> 00:16:03,010
You r l pass in that value.

246
00:16:03,280 --> 00:16:09,160
Then upon completion we get returned contributions.

247
00:16:09,310 --> 00:16:13,330
So now we have access to both of these returned image and return contributions.

248
00:16:13,350 --> 00:16:18,040
So we can go ahead and take this repo cut it and pasted in here.

249
00:16:18,280 --> 00:16:22,620
And for the image I can set returned image.

250
00:16:22,690 --> 00:16:24,170
Oops I missed my comma there.

251
00:16:24,340 --> 00:16:27,810
And for the contributors I can set.

252
00:16:28,360 --> 00:16:30,120
I guess it's returned contributions.

253
00:16:30,250 --> 00:16:30,670
There we go.

254
00:16:30,670 --> 00:16:32,350
Returned contributions.

255
00:16:32,350 --> 00:16:33,770
Very very cool.

256
00:16:33,780 --> 00:16:39,690
So and then at the very end what I can do is I can return that repo.

257
00:16:40,060 --> 00:16:42,810
But you know what you're going to notice there's a problem.

258
00:16:42,970 --> 00:16:46,930
Unexpected non void return value in void function.

259
00:16:46,930 --> 00:16:52,990
That's because when we're using closures you cannot return out of a closure you get trapped and that's

260
00:16:52,990 --> 00:16:57,210
why it's super important to use a completion handler with an escaping closure.

261
00:16:57,310 --> 00:16:59,370
So get rid of the return.

262
00:16:59,500 --> 00:17:04,350
And what we're going to do is we're going to go ahead and call completion make it escaping.

263
00:17:05,500 --> 00:17:06,890
We're going to.

264
00:17:06,970 --> 00:17:07,420
Whoops.

265
00:17:07,420 --> 00:17:09,040
Looks like I missed that.

266
00:17:09,040 --> 00:17:12,690
We're going to pass in a function return an empty function.

267
00:17:12,970 --> 00:17:19,210
And remember underscore for the property and what we're going to return this function is just a repo

268
00:17:19,360 --> 00:17:20,950
right just like we were returning.

269
00:17:20,950 --> 00:17:27,760
But we need to just type Ribault of type Ribault and we create one here so we can call our completion

270
00:17:27,760 --> 00:17:32,860
handler in the same place and pass in repo.

271
00:17:33,280 --> 00:17:39,400
So now as we go through we'll get all the values we'll download the image contributor's data and return

272
00:17:39,460 --> 00:17:40,730
the completed repo.

273
00:17:40,780 --> 00:17:43,260
That's exactly exactly what we want.

274
00:17:43,300 --> 00:17:46,750
So it looks like we are getting an issue here.

275
00:17:46,750 --> 00:17:50,710
It's saying we're missing our parameter here so I'm going to actually rewrite the function to show you

276
00:17:50,710 --> 00:17:52,160
what it should look like.

277
00:17:52,270 --> 00:17:58,420
We're going to call self-direct download trending repo K from dictionary and that is dict as we passed

278
00:17:58,420 --> 00:18:01,320
in from our for loop and the completion handler.

279
00:18:01,510 --> 00:18:04,230
We're going to get a returned repo.

280
00:18:04,390 --> 00:18:05,170
Right.

281
00:18:05,320 --> 00:18:10,970
And that is where we can append our returned repo to our returned repots array.

282
00:18:11,230 --> 00:18:13,480
But we're not passing in the proper repo.

283
00:18:13,570 --> 00:18:18,980
So we're going to go ahead and call download trending repo but you'll notice it's all exed out.

284
00:18:19,120 --> 00:18:24,880
And that's because we are setting it as a property which we needed to before but now we don't.

285
00:18:24,910 --> 00:18:32,420
So go ahead and just pass in the dictionary and on completion we're going to just get a returned repo.

286
00:18:32,440 --> 00:18:38,290
Remember right here in our function we pass in the repo to the completion handler once we have the image.

287
00:18:38,440 --> 00:18:45,990
Once we have the contributor's data and now inside here we can append our returned repo.

288
00:18:46,000 --> 00:18:50,160
So instead of returning that repo return the returned repo.

289
00:18:50,390 --> 00:18:50,900
OK.

290
00:18:51,100 --> 00:18:52,180
So that will go through.

291
00:18:52,330 --> 00:18:53,400
That will all do its thing.

292
00:18:53,410 --> 00:18:58,540
And then at the very end once this for loop is finished we will return the whole array back to wherever

293
00:18:58,540 --> 00:18:59,210
we call this.

294
00:18:59,210 --> 00:19:01,350
So let's go ahead and let's try it out.

295
00:19:01,660 --> 00:19:07,340
Let's go ahead and call download service instance download.

296
00:19:07,820 --> 00:19:08,980
Let's think what was it.

297
00:19:08,980 --> 00:19:15,360
Download a trending repo's I believe it's going to actually return all the values we need.

298
00:19:15,370 --> 00:19:16,880
This will be read.

299
00:19:17,170 --> 00:19:26,140
Well let's just call it repots array and we'll print out repots array dashes zero and we're gonna take

300
00:19:26,140 --> 00:19:31,540
the image and I'm going to print out the size because if we actually get a real image should print out

301
00:19:31,540 --> 00:19:34,070
a size for us so let's go ahead and build and run.

302
00:19:34,180 --> 00:19:39,460
Let's go test this we're doing a lot of kind of finicky data stuff but to make sure that we're casting

303
00:19:39,460 --> 00:19:41,670
it properly we're going to just see how we do.

304
00:19:41,690 --> 00:19:44,000
Let's let's go ahead and check it out.

305
00:19:44,050 --> 00:19:44,570
OK.

306
00:19:44,680 --> 00:19:46,090
So we're getting a problem here.

307
00:19:46,110 --> 00:19:50,080
It's saying unexpectedly found nyl while unwrapping an optional value.

308
00:19:50,250 --> 00:19:53,770
What we're going to do is we're going to head over to the next video and we're going to troubleshoot

309
00:19:53,770 --> 00:19:54,040
this.

310
00:19:54,040 --> 00:19:58,270
We're going to figure out why we're getting optional values why things aren't coming in the way we want

311
00:19:58,750 --> 00:20:00,580
and we'll see in the next video.

312
00:20:00,580 --> 00:20:02,720
So let's head over to the next one and let's fix this problem.
