1
00:00:04,980 --> 00:00:10,320
Plug them back ladies and gentlemen Mark Price here at DEF slopes dot com and we're going to continue

2
00:00:10,320 --> 00:00:12,060
building our coater swag app.

3
00:00:12,240 --> 00:00:17,500
So far we have the collection view cell in place from the last video the UI for it at least.

4
00:00:17,550 --> 00:00:22,890
And I think what we need to do now is start building out some of our data Carco the data in the app

5
00:00:22,920 --> 00:00:27,330
as well as our data model that we're going to need to host that data.

6
00:00:27,330 --> 00:00:32,100
And the reason why I like to build you whine and go into the data before I actually maybe work in the

7
00:00:32,100 --> 00:00:35,910
view controllers is because sometimes you can't move forward without data or you can build your view

8
00:00:35,910 --> 00:00:36,310
controller.

9
00:00:36,330 --> 00:00:39,980
But how do I pass data from one screen to the other if it doesn't even exist.

10
00:00:40,140 --> 00:00:44,370
And how can I show data on the cell even if it doesn't exist.

11
00:00:44,370 --> 00:00:50,980
And so close to that first so what we're going to do is we're going to go into our model folder here.

12
00:00:51,180 --> 00:00:55,530
We're going to create a new file We're going to call this a swift file here and we're going to call

13
00:00:55,530 --> 00:00:58,950
this product.

14
00:00:59,340 --> 00:01:02,050
You can have multiple products just like you can have multiple categories.

15
00:01:02,070 --> 00:01:05,520
We'll make this a struct as well.

16
00:01:05,520 --> 00:01:08,030
Always use a struct unless you absolutely need a class.

17
00:01:08,070 --> 00:01:10,260
That's the rule of thumb so let's make a struct.

18
00:01:10,260 --> 00:01:15,090
All right and what we're going to do is just just like we do with the category we're going to have the

19
00:01:15,230 --> 00:01:23,050
data that we need chrism variables initialiser things like that so private set public var and we're

20
00:01:23,050 --> 00:01:32,550
going to say tidal type String private set public var a price y making price as a string instead of

21
00:01:32,550 --> 00:01:36,990
a dollar sign while we're not actually using those numbers X for anything except the display.

22
00:01:36,990 --> 00:01:39,740
And when you make a purchase it would probably happen on the back end anyway.

23
00:01:40,070 --> 00:01:45,780
And so a string is completely appropriate and it will become a string at one point anyway.

24
00:01:46,090 --> 00:01:47,020
When you have to display.

25
00:01:47,040 --> 00:01:53,850
And then the textfield so public var image name like we've done before as well to of type String.

26
00:01:53,850 --> 00:01:59,280
Let's create our initialiser at just press enter on the autocomplete there and we're going to say title

27
00:01:59,370 --> 00:02:05,930
of type String price of type String image name of type string.

28
00:02:06,480 --> 00:02:13,800
And then just like we did before on the category's self that title equals title itself that price equals

29
00:02:13,800 --> 00:02:19,160
price and self dot image name equals image name.

30
00:02:19,170 --> 00:02:21,350
All right we've got our product model.

31
00:02:21,360 --> 00:02:22,230
It's looking good.

32
00:02:22,260 --> 00:02:29,220
Let's just put this space here for good measure and let's go to our services now and what we want to

33
00:02:29,220 --> 00:02:33,470
do is we want to create a service that allows us to get whatever product that we need.

34
00:02:33,600 --> 00:02:38,350
And we know that we have hats hoodies et cetera et cetera et cetera.

35
00:02:38,580 --> 00:02:44,280
So what we're going to do is create a few different variables here for those products.

36
00:02:44,310 --> 00:02:48,700
So what we're going to do and we'll start off with hats just for fun.

37
00:02:48,810 --> 00:02:53,530
Private let hat equals and we're just like we did appear with categories.

38
00:02:53,580 --> 00:02:59,010
We're going to create some products so it's going to be a product and then it's going to ask for certain

39
00:02:59,010 --> 00:03:00,900
things like title price et cetera.

40
00:03:00,900 --> 00:03:02,330
We've done this before right.

41
00:03:02,370 --> 00:03:09,020
So I'm getting this information from our merchandise images.

42
00:03:09,090 --> 00:03:11,410
So we've got these hats and hoodies and things like that.

43
00:03:11,430 --> 00:03:14,290
And I'm just going to make the prices up and everything.

44
00:03:14,400 --> 00:03:16,000
So just follow along.

45
00:03:17,120 --> 00:03:19,130
And let's make some data.

46
00:03:19,130 --> 00:03:26,530
So the title is going to be Deb slopes logo graphic beanie.

47
00:03:26,850 --> 00:03:27,540
OK.

48
00:03:27,650 --> 00:03:34,980
The price is going to be $18 and the image name is hat 01 PMG.

49
00:03:35,600 --> 00:03:36,010
OK.

50
00:03:36,200 --> 00:03:37,480
So there's our first product.

51
00:03:37,490 --> 00:03:38,420
We're going to type all these out.

52
00:03:38,420 --> 00:03:42,820
So this is really boring for you can speed up a copy and paste the code in the project.

53
00:03:42,830 --> 00:03:46,970
The reason why I don't copy and paste all the stuff over again is because it's important for you to

54
00:03:46,970 --> 00:03:53,810
type as a new programmer and never ever has anybody ever been like I wish were sold to copy and paste

55
00:03:53,810 --> 00:03:55,100
more when they're teaching.

56
00:03:55,100 --> 00:03:56,300
It's always the opposite.

57
00:03:56,300 --> 00:03:58,910
Why are they keeping a pacing I can't keep up I don't know what they just did.

58
00:03:58,910 --> 00:04:01,960
So we're just going to write these all out here.

59
00:04:01,970 --> 00:04:03,130
No big deal.

60
00:04:03,290 --> 00:04:04,430
It's all part of the process.

61
00:04:04,430 --> 00:04:05,480
Lots of fun.

62
00:04:05,660 --> 00:04:07,210
Logo hat black.

63
00:04:07,280 --> 00:04:10,640
I'm putting in different products here and these values actually don't matter.

64
00:04:10,640 --> 00:04:14,140
The only one that really matters here is the image name because we're pulling it from the desk.

65
00:04:14,150 --> 00:04:20,660
This other stuff is just titles and descriptions so you can put whatever you want there actually make

66
00:04:20,660 --> 00:04:21,650
another product.

67
00:04:21,650 --> 00:04:28,710
I am putting commas at the end of these here so we're going to have 0 3 now so this is going to be dev

68
00:04:28,770 --> 00:04:32,370
slopes logo hat white.

69
00:04:32,510 --> 00:04:41,810
The price is $22 and the image name is hat 0 3 that P and G comma and the final product in the hat series

70
00:04:41,900 --> 00:04:47,760
is going to be the slopes logo snap back.

71
00:04:47,900 --> 00:04:49,670
And this price will make it a little bit cheaper.

72
00:04:49,730 --> 00:04:50,540
$20.

73
00:04:50,540 --> 00:04:58,040
And the image name is going to be zero for you as crazy as when I was a kid like flex felt hats were

74
00:04:58,220 --> 00:05:02,270
all the rage like all the rage and now you can hardly find them anywhere.

75
00:05:02,270 --> 00:05:04,720
Everyone's into the snacks which were all the rage in the 80s.

76
00:05:04,730 --> 00:05:09,800
You know less like truck drivers where you know there are beer bellies and their hair coming out of

77
00:05:09,800 --> 00:05:12,670
the front of their hats it was disgusting.

78
00:05:12,830 --> 00:05:14,670
And now it's like it's back in style again.

79
00:05:14,660 --> 00:05:18,030
You go to any store like Zumiez or Pac Sun or anything like that.

80
00:05:18,030 --> 00:05:20,820
There's no flex it's all nasty snap backs.

81
00:05:20,880 --> 00:05:24,830
Well anyway hats.

82
00:05:25,040 --> 00:05:27,610
So next thing we're going to do is the hoodies.

83
00:05:27,620 --> 00:05:35,690
All right so private let hoodies equals and just make more products.

84
00:05:35,690 --> 00:05:41,000
And again these would normally be on a server unless your app is hardcoded like this which a lot of

85
00:05:41,090 --> 00:05:45,570
new developers or simple apps have hardcoded information like this.

86
00:05:45,590 --> 00:05:52,930
So this is their slopes logo the grey The price is going to be $32.

87
00:05:52,970 --> 00:05:59,290
And the image name is going to be Pootie 0 1 p and G comma.

88
00:05:59,450 --> 00:06:05,250
You know we can do here is we can just copy and paste it from our existing stuff.

89
00:06:05,280 --> 00:06:09,300
So 1 how many Hoodie's we have forced to.

90
00:06:09,380 --> 00:06:14,510
So what we can do is change the images so I know this is the two and three and four.

91
00:06:14,570 --> 00:06:15,810
And then we can just change that text.

92
00:06:15,830 --> 00:06:19,410
So the second one is Dove soaps logo be red.

93
00:06:19,550 --> 00:06:28,550
Same price and then slopes low def slopes the gray OK same price in the last one the slopes the black

94
00:06:29,840 --> 00:06:32,140
like so little bit or doing it that way.

95
00:06:32,150 --> 00:06:33,750
So there's our hoodies.

96
00:06:33,770 --> 00:06:36,800
Let's do our shirts and then our shirts we have five of them.

97
00:06:36,800 --> 00:06:41,600
So private let shirts equals.

98
00:06:41,990 --> 00:06:42,380
All right.

99
00:06:42,530 --> 00:06:44,880
And still a product like so.

100
00:06:45,740 --> 00:06:56,570
And the title for a shirt is going to be Dev's slopes logo shirt black and the price is $18.

101
00:06:56,920 --> 00:07:03,880
So Image Name is going to be shirt 0 1 that P and G and will do the same thing here will copy and paste

102
00:07:03,880 --> 00:07:09,910
these few items from what we've already typed and then we'll just modify them two three four five.

103
00:07:09,910 --> 00:07:11,740
Get rid of that last comma there.

104
00:07:11,860 --> 00:07:14,030
Otherwise we'll have a syntax error.

105
00:07:14,170 --> 00:07:18,900
And so the first one is def slopes logo shirt black slopes badge.

106
00:07:19,120 --> 00:07:28,150
So this one's depth slopes badge shirt light gray and shirt 0 2 and the third one is def slopes logo

107
00:07:28,210 --> 00:07:31,180
shirt red OK.

108
00:07:31,590 --> 00:07:39,060
And then the third one is hustle delegate gray or the excuse me the fourth one is Cosel delegate grab

109
00:07:39,110 --> 00:07:44,940
by the way these shirts are all available at coater swag dot com available to purchase.

110
00:07:44,990 --> 00:07:50,220
So you can look cool just like me even though I'm not wearing any of this right now.

111
00:07:50,240 --> 00:07:51,340
Hustle delegate.

112
00:07:51,410 --> 00:07:53,010
I do own the merchandise though.

113
00:07:53,150 --> 00:07:58,410
So 0 1 0 2 0 3 on the shirt 0 4 on this shirt.

114
00:07:58,550 --> 00:07:59,640
Let's just change the price.

115
00:07:59,640 --> 00:08:01,990
And the second one $219 just for fun.

116
00:08:02,300 --> 00:08:08,160
And on the fifth one this one is kickflip studios studios black.

117
00:08:08,260 --> 00:08:16,280
This is our games to do that we are building up and shert 05 that looks good for the shirts.

118
00:08:16,280 --> 00:08:20,060
The last one is digital good and other digital goods has nothing.

119
00:08:20,090 --> 00:08:26,540
So what we want to do is say private let digital goods equals and we'll just make an empty array of

120
00:08:26,540 --> 00:08:29,070
type product OK.

121
00:08:29,120 --> 00:08:35,330
We can't just make an empty array like this because in swift You have to declare a type OK whether it's

122
00:08:35,480 --> 00:08:39,450
explicitly the card or implicitly rather inferred.

123
00:08:39,470 --> 00:08:40,550
You have to have a type.

124
00:08:40,550 --> 00:08:45,940
So what we're going to is going to create an empty array of type product and putting the print that

125
00:08:45,940 --> 00:08:48,790
is at the end actually creates an empty array.

126
00:08:49,010 --> 00:08:49,350
OK.

127
00:08:49,370 --> 00:08:50,330
And there's nothing in it.

128
00:08:50,360 --> 00:08:55,370
Why did we have to do that at all well when our collection view was feeding off of this data.

129
00:08:55,730 --> 00:08:57,480
It's going to need to get an array of some kind.

130
00:08:57,480 --> 00:09:02,140
And if we don't have an empty array we'll have something that's nil and the app will crash.

131
00:09:02,200 --> 00:09:02,460
OK.

132
00:09:02,480 --> 00:09:04,030
So this is very important.

133
00:09:04,430 --> 00:09:04,750
OK.

134
00:09:04,760 --> 00:09:06,140
So very cool.

135
00:09:06,140 --> 00:09:12,020
So we got our actual data now and what I want to do now is create a function that's like get products

136
00:09:12,020 --> 00:09:17,630
for a specific category so basically the ideas you pass and a category title and it gets the appropriate

137
00:09:17,630 --> 00:09:20,010
product array for that title.

138
00:09:20,450 --> 00:09:26,200
So we're in a funk get products move this down a little here.

139
00:09:27,680 --> 00:09:38,480
Move up rather to get products for category title and the variable named title we just give the parameter

140
00:09:38,480 --> 00:09:45,010
a name and it's going to return an array of type product and what we'll do is we'll create a switch

141
00:09:45,010 --> 00:09:51,250
statement a switch statement to help us decide which which array to return.

142
00:09:51,250 --> 00:09:54,480
And so we're going to say title.

143
00:09:54,550 --> 00:10:01,180
So we're going to we're going to see what title was passed in here and in this case if the case is shirts

144
00:10:01,750 --> 00:10:04,030
we're going to return shirts but we don't have any functions yet for that.

145
00:10:04,030 --> 00:10:09,160
So next thing we need to do is create a few empty functions so we can finish off or switch David so

146
00:10:09,850 --> 00:10:20,990
function get hats and we're going to return a product like so and let's do the other ones.

147
00:10:22,860 --> 00:10:32,330
Phunk get these return of type product on X coats.

148
00:10:32,510 --> 00:10:41,330
Stick with me or stop going all the way to the bottom here phunk get shirts up type

149
00:10:43,970 --> 00:10:55,860
product like so and then digital goods phunk get digital goods type product.

150
00:10:55,870 --> 00:11:01,020
All right now we're not returning a thing yet so it's going to yell at us but at least we can finish

151
00:11:01,020 --> 00:11:08,500
this now so now with the shirts I can say get shirts and then I'll do is copy this for the other three

152
00:11:08,500 --> 00:11:12,900
categories here so one two three.

153
00:11:12,910 --> 00:11:24,220
So get shirts or hats or booties doesn't matter what order it's in or digital.

154
00:11:24,650 --> 00:11:26,060
And we can do default here.

155
00:11:26,060 --> 00:11:31,390
The default will be get shirts in case it didn't match any of these cases here which it will of course.

156
00:11:31,400 --> 00:11:38,090
But to get that and then what is is going to be get hoodies it's yelling at us again because we're not

157
00:11:38,090 --> 00:11:38,970
returning anything.

158
00:11:38,990 --> 00:11:43,000
And then this one's going to be good digital goods.

159
00:11:43,040 --> 00:11:44,150
So does this make sense.

160
00:11:44,150 --> 00:11:45,940
We obviously need to know.

161
00:11:46,580 --> 00:11:50,800
We need to know which type of category that we're getting the product array for.

162
00:11:50,930 --> 00:11:51,620
OK.

163
00:11:52,790 --> 00:12:05,140
And what we need to do in each of these cases is return them return return return return and return

164
00:12:06,050 --> 00:12:06,920
cool.

165
00:12:07,420 --> 00:12:09,120
So that looks good to me.

166
00:12:09,160 --> 00:12:18,840
And then in these cases here which need to return the appropriate data so we can return that's return

167
00:12:18,930 --> 00:12:23,350
but he's return shirts.

168
00:12:23,540 --> 00:12:27,260
And so what I want and weirdo.

169
00:12:27,260 --> 00:12:31,630
All right shirts and return digital goods.

170
00:12:31,690 --> 00:12:34,150
So all these heirs should go here.

171
00:12:34,180 --> 00:12:34,380
OK.

172
00:12:34,390 --> 00:12:39,790
So what's going to happen is like our view controller when it's filling out the information for the

173
00:12:39,820 --> 00:12:43,510
collection to sell it's going to when we go onto the screen.

174
00:12:43,510 --> 00:12:47,350
So from the product when we select that specific product let's say we select shirts we're going to select

175
00:12:47,350 --> 00:12:51,040
shirts go to the next view controller with the collection view and then it's going to call this function

176
00:12:51,370 --> 00:12:52,470
get products for category.

177
00:12:52,490 --> 00:12:57,820
Time will pass in the title and then we'll return the appropriate array of data based on that title

178
00:12:57,820 --> 00:13:01,720
and this is also similar how you might do it if you were talking to a web server that you would pass

179
00:13:01,720 --> 00:13:01,920
up.

180
00:13:01,920 --> 00:13:06,000
Hey I want the shirts and you would let the server know and the server would send you back this data.

181
00:13:06,010 --> 00:13:07,450
Very very similar.

182
00:13:07,450 --> 00:13:11,740
So we got our hats hoodies products etc. This is looking really good.

183
00:13:11,980 --> 00:13:13,600
So cool.

184
00:13:13,600 --> 00:13:14,650
I'm going to call this video done.

185
00:13:14,650 --> 00:13:19,720
We just kind of set up our data and now we have everything that we need to actually go forth and build

186
00:13:19,720 --> 00:13:22,450
out our collection to sell and show data in it and we're getting really close here.

187
00:13:22,450 --> 00:13:26,860
So it's not that complex compared to the table view very very similar.

188
00:13:26,860 --> 00:13:29,170
And we're making great progress so that's it for now.

189
00:13:29,170 --> 00:13:31,260
Marc price advice Lopes dotcom.

190
00:13:31,360 --> 00:13:32,310
See you soon.

