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