1
00:00:08,110 --> 00:00:12,780
Hey everybody what's going on this is Caleb with deps Lopes dot com and in the last video we were having

2
00:00:12,780 --> 00:00:18,060
some trouble we were having a crash because one of our values was returned as nil.

3
00:00:18,060 --> 00:00:19,240
And that is a problem.

4
00:00:19,260 --> 00:00:21,860
So we're going to go ahead and figure out the source of this issue.

5
00:00:21,870 --> 00:00:26,050
So let's pull open our escort project and I want you to take a look here.

6
00:00:26,130 --> 00:00:28,480
We've got a crash on contributor's.

7
00:00:28,500 --> 00:00:30,030
You r l k.

8
00:00:30,080 --> 00:00:34,300
We're trying to access the property here contributor's you are l.

9
00:00:34,530 --> 00:00:40,770
And if you look at the get hub API that is the name right contributor's underscore you are l So what

10
00:00:40,770 --> 00:00:42,050
is the problem.

11
00:00:42,360 --> 00:00:42,960
Let me show you.

12
00:00:42,960 --> 00:00:48,520
This is the danger of doing things strongly using lots of strings.

13
00:00:48,570 --> 00:00:54,300
Really we should be casting all of these as their own constants like we did with the elves here to make

14
00:00:54,300 --> 00:00:56,290
sure that we don't miss typed them ever.

15
00:00:56,730 --> 00:01:00,430
But we're going to go ahead and we'll have to do that and in a later video to fix that.

16
00:01:00,450 --> 00:01:02,040
But for now check it out.

17
00:01:02,040 --> 00:01:08,340
Contributor's you are l and watch what happens when I create this originally contributor's you are l.

18
00:01:08,340 --> 00:01:09,600
That's great.

19
00:01:09,600 --> 00:01:17,550
But look when I create the dictionary individually I forgot the ass contributor for your L-1 single

20
00:01:17,550 --> 00:01:18,650
contributor.

21
00:01:18,690 --> 00:01:24,600
So without the apps this dictionary does not know how to find this because this key doesn't exist.

22
00:01:24,600 --> 00:01:26,530
So I added the s right there.

23
00:01:26,550 --> 00:01:31,620
I just added it and let's build and run let's see if this fixes our problem one single letter could

24
00:01:31,620 --> 00:01:33,720
have been the cause for that entire crash.

25
00:01:33,720 --> 00:01:34,660
Let's go check it out.

26
00:01:36,030 --> 00:01:36,740
Here we go.

27
00:01:36,750 --> 00:01:44,220
And if you remember in our trending feed Visi were trying to print out the image the way that we the

28
00:01:44,220 --> 00:01:44,820
way that we want.

29
00:01:44,820 --> 00:01:48,900
So repots array the first one the image and print out image size.

30
00:01:48,900 --> 00:01:50,070
But check it out.

31
00:01:50,280 --> 00:01:51,530
Index out of range.

32
00:01:51,530 --> 00:01:56,010
Fatal error index out of range so it looks like that is not working as well.

33
00:01:56,010 --> 00:02:00,360
So it looks like it's not allowing us to return our repo the way we want.

34
00:02:00,360 --> 00:02:04,370
This is coming in as knows well trending repots array.

35
00:02:04,370 --> 00:02:06,720
For some reason is coming in as Knill.

36
00:02:06,950 --> 00:02:12,540
Interesting and let's see that's from Alamo fire itself.

37
00:02:12,540 --> 00:02:14,490
So let's think about what we're doing here.

38
00:02:14,490 --> 00:02:16,280
Let's go into our download service.

39
00:02:16,410 --> 00:02:20,680
Let's close the console there let's stop the app from running.

40
00:02:20,880 --> 00:02:27,390
And let's think first we downloaded all the data and that's good that comes in properly we know that

41
00:02:27,390 --> 00:02:28,660
already.

42
00:02:28,660 --> 00:02:28,970
Okay.

43
00:02:28,980 --> 00:02:29,460
And you know what.

44
00:02:29,460 --> 00:02:31,710
Actually we have changed it since we first ran it.

45
00:02:31,710 --> 00:02:38,100
So let's go ahead and head back to trending feed Visi let's comment this out and then let's call download

46
00:02:38,100 --> 00:02:46,770
service that in that instance got download trending repo's dict Auray we'll just say dict are notes

47
00:02:46,770 --> 00:02:50,180
in array so I guess we'll just well dict array both.

48
00:02:50,310 --> 00:02:57,300
So we're going to go ahead and print dict array and let's run this let's make sure that we are getting

49
00:02:57,300 --> 00:02:59,430
the data we want whenever you change these functions.

50
00:02:59,430 --> 00:03:03,050
It's important to test them to make sure that they work the same way that you expect.

51
00:03:03,270 --> 00:03:09,100
So here we go pulling out downloading.

52
00:03:09,310 --> 00:03:09,820
And here we go.

53
00:03:09,820 --> 00:03:10,330
Okay good.

54
00:03:10,330 --> 00:03:12,750
So all the data is coming in the way we want.

55
00:03:12,750 --> 00:03:14,170
That's perfect.

56
00:03:14,170 --> 00:03:15,280
Very cool.

57
00:03:15,280 --> 00:03:17,070
So that one is good.

58
00:03:17,830 --> 00:03:20,320
Let's go ahead and head back let's look.

59
00:03:20,320 --> 00:03:25,660
When we get our trending repots array that works the way we want.

60
00:03:25,660 --> 00:03:26,380
Perfect.

61
00:03:26,380 --> 00:03:32,370
So then downloading trending repo's we pass in the repo's directory from this other function.

62
00:03:32,650 --> 00:03:35,990
We go through we call it download trending repo.

63
00:03:36,230 --> 00:03:39,690
All right we pass in the dictionary we return the repo.

64
00:03:39,910 --> 00:03:41,160
Then we append it.

65
00:03:41,600 --> 00:03:48,040
OK so let's go ahead and let's call that one and let's see how that works download service instance

66
00:03:48,370 --> 00:03:50,680
download trending repo's.

67
00:03:50,770 --> 00:03:56,540
And here we go we get returned repo's let's just print.

68
00:03:56,800 --> 00:04:05,520
Whoops returned repo's and let's just print out the first one and let's print out the name.

69
00:04:05,890 --> 00:04:11,200
OK let's just double check make sure everything's working all of the data is getting transferred the

70
00:04:11,200 --> 00:04:14,530
way it's supposed to.

71
00:04:14,550 --> 00:04:16,360
Let's identify this problem.

72
00:04:17,880 --> 00:04:18,440
Here we go.

73
00:04:21,340 --> 00:04:21,990
OK.

74
00:04:22,070 --> 00:04:25,160
So it looks like this may be a part of our problem here.

75
00:04:25,160 --> 00:04:28,040
Let's go back let's look.

76
00:04:28,040 --> 00:04:28,340
All right.

77
00:04:28,340 --> 00:04:35,930
Trending repots array is not being able to be not being able to do what it's supposed to do.

78
00:04:36,090 --> 00:04:39,120
So let's figure out why we are calling.

79
00:04:39,540 --> 00:04:43,770
We create our repulsor right here we download the data we know that works.

80
00:04:43,770 --> 00:04:47,270
So our for loop is good as well because we're cycling through all of them.

81
00:04:47,550 --> 00:04:50,520
Download trending Ribault we pass in the dictionary.

82
00:04:50,540 --> 00:04:51,240
OK that's good.

83
00:04:51,240 --> 00:04:54,320
And then let's look in download trending repo to see.

84
00:04:54,330 --> 00:04:56,310
We passed in the dictionary.

85
00:04:56,520 --> 00:04:58,400
We create all these properties.

86
00:04:58,440 --> 00:05:06,320
Avatar you are l contributors you are all named description fork's count language.

87
00:05:06,340 --> 00:05:10,130
Tim you r l k let's make sure everything else is good here.

88
00:05:10,240 --> 00:05:16,490
Name description language avatar you are l that looks good.

89
00:05:19,600 --> 00:05:19,900
OK.

90
00:05:19,970 --> 00:05:21,550
Index out of range.

91
00:05:21,590 --> 00:05:28,190
This makes me think that perhaps we are asking for one number somewhere and then asking for another

92
00:05:28,340 --> 00:05:31,880
number elsewhere.

93
00:05:34,090 --> 00:05:35,390
Think think think so.

94
00:05:35,590 --> 00:05:38,000
We are passing in our dictionary here.

95
00:05:38,350 --> 00:05:41,500
When we pass in the dictionary we get all those values.

96
00:05:41,500 --> 00:05:48,550
We download the image we download the contributor's data we create a repo and then we then we return

97
00:05:49,040 --> 00:05:50,620
that singular repo.

98
00:05:50,620 --> 00:05:51,540
That's good.

99
00:05:51,880 --> 00:05:53,170
OK that's great.

100
00:05:53,170 --> 00:05:57,120
So let's go back and let's look at this download trending repo's.

101
00:05:57,370 --> 00:05:58,310
That looks good.

102
00:05:58,420 --> 00:06:04,790
OK so it looks like we're downloading everything we're going through all the dictionaries appending

103
00:06:04,810 --> 00:06:06,000
it.

104
00:06:06,460 --> 00:06:09,110
But we're still having some trouble here.

105
00:06:09,220 --> 00:06:14,620
OK so how about this what if oh ok so how about this.

106
00:06:14,620 --> 00:06:17,520
I think I know what the problem is we are going through.

107
00:06:17,530 --> 00:06:20,820
And once we get into this closure we can't escape.

108
00:06:20,820 --> 00:06:25,310
So let's try pasting our completion handler inside our for loop.

109
00:06:25,900 --> 00:06:30,000
Well you know I think that'll it'll return a new array every time it's not very efficient.

110
00:06:30,040 --> 00:06:34,510
Let's see if it fixes our problem though because I don't think we're really out of range.

111
00:06:34,510 --> 00:06:37,120
I don't think that's the problem.

112
00:06:37,150 --> 00:06:40,790
OK let's go ahead and see where we go.

113
00:06:41,100 --> 00:06:44,390
And we are calling trending repo's right.

114
00:06:46,490 --> 00:06:46,850
Yes.

115
00:06:46,900 --> 00:06:47,790
Download training repo's.

116
00:06:47,800 --> 00:06:48,450
Very cool.

117
00:06:48,730 --> 00:06:49,020
OK.

118
00:06:49,060 --> 00:06:51,670
So we're still getting an issue here.

119
00:06:51,700 --> 00:06:54,290
We're not getting the functions back that we need.

120
00:06:54,310 --> 00:06:55,340
So this is not good.

121
00:06:55,420 --> 00:07:00,040
Let's go ahead let's put some breakpoints in here to see what the problem is let's make sure that we're

122
00:07:00,040 --> 00:07:02,880
actually getting at least one.

123
00:07:03,010 --> 00:07:04,280
So let's build and run.

124
00:07:04,570 --> 00:07:07,940
Let's see if we're getting any data passed in into this function.

125
00:07:11,200 --> 00:07:15,160
It's going to build and run Riego.

126
00:07:15,310 --> 00:07:15,980
All right.

127
00:07:16,560 --> 00:07:16,900
OK.

128
00:07:16,900 --> 00:07:17,590
So interesting.

129
00:07:17,590 --> 00:07:24,580
This is causing a problem our breakpoint is never actually getting called so that's extra tricky.

130
00:07:24,580 --> 00:07:27,390
Let's go ahead and let's think about how we could fix this.

131
00:07:27,700 --> 00:07:34,180
Well we could count against the number of repos coming into our array and then once it gets to a certain

132
00:07:34,180 --> 00:07:36,180
amount we could return it.

133
00:07:36,570 --> 00:07:38,070
Let's let's try that out.

134
00:07:38,080 --> 00:07:42,020
So inside self download trending repo.

135
00:07:42,130 --> 00:07:50,860
Go ahead and call if repo re count is less than nine.

136
00:07:50,860 --> 00:07:55,180
Let's go ahead and think about what we're going to do if it's less than nine.

137
00:07:55,180 --> 00:07:56,830
We want to append it.

138
00:07:57,040 --> 00:07:57,860
OK.

139
00:07:58,330 --> 00:08:03,820
But if it's not less than nine we want to go ahead and call completion because that is when we will

140
00:08:03,820 --> 00:08:05,030
know that we're finished.

141
00:08:05,130 --> 00:08:05,370
OK.

142
00:08:05,380 --> 00:08:06,000
That's pretty cool.

143
00:08:06,020 --> 00:08:08,490
I will I think solve our problem here.

144
00:08:08,500 --> 00:08:16,440
Let's go ahead and let's run the simulator and let's make sure that we're not going to run out of our

145
00:08:16,440 --> 00:08:17,160
index.

146
00:08:17,160 --> 00:08:20,130
That's what we are doing we're currently out of index but we want to fix it.

147
00:08:20,130 --> 00:08:37,090
So here we go launching versey app.

148
00:08:37,270 --> 00:08:39,200
Ok so that is good.

149
00:08:39,200 --> 00:08:43,070
We are getting the information we need.

150
00:08:43,070 --> 00:08:44,410
Looks like it's working now.

151
00:08:44,630 --> 00:08:50,030
So we returned the first item in the repository and that's great.

152
00:08:50,060 --> 00:08:55,080
That's super cool although you know what I think let's let's look back at our download service.

153
00:08:55,160 --> 00:09:00,470
We're saying if the repo's array count is less than 9 but if I remember properly the repulsor rate can

154
00:09:00,470 --> 00:09:01,460
go up to 10.

155
00:09:01,460 --> 00:09:03,370
So let's set that to actually be 10.

156
00:09:03,560 --> 00:09:08,450
Let's run this again because it looks like we're missing our first element because Alamo fire if I remember

157
00:09:08,450 --> 00:09:09,720
properly let me look.

158
00:09:09,770 --> 00:09:12,650
But I think it was the second element.

159
00:09:12,710 --> 00:09:15,890
First we get swift and then next we get allemande fire.

160
00:09:15,890 --> 00:09:18,670
So that shouldn't be the item at index 0.

161
00:09:19,160 --> 00:09:23,600
But let's go ahead and let's build and run let's see if adding that extra one is going to give us what

162
00:09:23,600 --> 00:09:24,070
we need.

163
00:09:27,390 --> 00:09:37,480
It's running through doing all of its downloading and we're not getting anything printing just yet.

164
00:09:37,540 --> 00:09:37,970
Ha.

165
00:09:38,080 --> 00:09:41,090
OK so it looks like it's not going to return.

166
00:09:41,090 --> 00:09:47,960
Let's let's go ahead and just leave it at 9:00 for now and then we're going to go ahead and actually

167
00:09:49,340 --> 00:09:51,170
modify that later on for now.

168
00:09:51,170 --> 00:09:52,910
At least we're getting some data returning.

169
00:09:52,910 --> 00:09:54,790
We might need to do some bug fixes later.

170
00:09:54,800 --> 00:09:55,720
But guys this is great.

171
00:09:55,730 --> 00:10:00,430
We made a fix we made a change and sometimes in programming that what you have to do.

172
00:10:00,490 --> 00:10:02,500
You have to make some changes to make it work.

173
00:10:02,510 --> 00:10:09,050
So I'm building and running one last time just so that we can see all the values that get returned and

174
00:10:09,110 --> 00:10:10,940
let's just let's check it out.

175
00:10:11,540 --> 00:10:13,340
OK so cool swift algorithm club.

176
00:10:13,340 --> 00:10:14,260
Interesting.

177
00:10:14,270 --> 00:10:21,050
So it appears that these are kind of coming in in a random order as if maybe like an image that's coming

178
00:10:21,050 --> 00:10:25,850
in is larger than another so it's taking longer to download so another one that's quicker is going ahead

179
00:10:25,850 --> 00:10:27,400
of time.

180
00:10:27,470 --> 00:10:31,660
So you know what I actually want to modify the repo's array here.

181
00:10:31,670 --> 00:10:38,900
Let's go ahead and just type let sorted array and it's going to be equal to repo's array.

182
00:10:38,960 --> 00:10:45,320
But we're going to call datt sorted and you'll see that you can basically compare to repo's and then

183
00:10:45,320 --> 00:10:47,480
do something depending on the sorting.

184
00:10:47,480 --> 00:10:52,100
So we're going to just press enter and the first one we'll call repo a.

185
00:10:52,130 --> 00:10:54,260
The second one we'll call repo B.

186
00:10:54,510 --> 00:10:57,940
And let's just say if repo a.

187
00:10:58,190 --> 00:11:00,310
If repo a dot.

188
00:11:00,470 --> 00:11:02,800
Well we're starting it by number of forks.

189
00:11:02,810 --> 00:11:08,630
So let's just go ahead and say If number of forks is greater than Ribault B.

190
00:11:08,780 --> 00:11:18,550
Number of forks we want to return true k and otherwise we're going to return false.

191
00:11:18,560 --> 00:11:23,870
And the reason for that is basically the sorted array is going to sort and organize things so it's going

192
00:11:23,870 --> 00:11:28,280
to take the first and the second items if one is greater is going to return true and that'll be at the

193
00:11:28,280 --> 00:11:30,910
top of the list then it's going to compare the next one.

194
00:11:31,130 --> 00:11:34,580
And basically what it's going to do is it's going to look through all of them and sort them and then

195
00:11:34,580 --> 00:11:36,900
return them to this nice beautiful array.

196
00:11:36,980 --> 00:11:43,230
Then once it's all sorted we're going to return the sorted array sorted array.

197
00:11:43,310 --> 00:11:44,540
Beautiful that's much better.

198
00:11:44,540 --> 00:11:46,140
So go ahead and build and run.

199
00:11:46,310 --> 00:11:48,280
And let's see if that helps.

200
00:11:48,410 --> 00:11:53,650
We should get swift as our very first item because that's going to have the most forks.

201
00:11:54,140 --> 00:11:55,920
So let's go ahead and run it.

202
00:11:56,150 --> 00:11:58,940
And we should get swift to print out the way we want

203
00:12:02,010 --> 00:12:05,760
go loading doing its thing and there we go.

204
00:12:05,760 --> 00:12:09,940
Swift is the first item because we have now properly sorted the data.

205
00:12:09,940 --> 00:12:14,060
It looks like it came in the wrong way so we had to sort it ourselves which is beautiful.

206
00:12:14,070 --> 00:12:15,690
But guys it's working now.

207
00:12:15,750 --> 00:12:20,370
We're going to move on to the next video where we're going to start putting these functions together

208
00:12:20,640 --> 00:12:24,060
to start making data show up in our table view cells.

209
00:12:24,060 --> 00:12:25,740
So so cool.

210
00:12:25,740 --> 00:12:29,820
So let's go ahead and let's head over to the next video and we're going to we're going to do that now.
