1
00:00:07,940 --> 00:00:10,640
Everybody this is Caleb with Debb sloped dotcom.

2
00:00:10,660 --> 00:00:15,730
And in this video we're going to set up our UI table view to show static data.

3
00:00:15,760 --> 00:00:17,850
OK we're going to just make sure our cells are working.

4
00:00:17,950 --> 00:00:21,910
Make sure we're good to go with configuring the cells we're also going to set up our table view which

5
00:00:21,910 --> 00:00:23,480
is also cool I guess.

6
00:00:23,620 --> 00:00:31,150
And we're also going to create an income so that we can properly display the goals type short term versus

7
00:00:31,150 --> 00:00:31,750
long term.

8
00:00:31,750 --> 00:00:37,060
So pull open that X code project and in the last video we set up our core data entity.

9
00:00:37,180 --> 00:00:39,820
But for now we're going to go into that goals.

10
00:00:39,820 --> 00:00:41,200
VC Okay.

11
00:00:41,440 --> 00:00:45,600
And we're going to set up our table view so that we can actually use it.

12
00:00:45,660 --> 00:00:51,340
Magine that we might well actually use our table view so down beneath our class outside of the class

13
00:00:51,580 --> 00:00:54,550
we're going to create an extension of Goles.

14
00:00:54,550 --> 00:00:57,540
VC so type extension goes.

15
00:00:57,540 --> 00:01:06,070
VC and we're going to conform to you Table View delegate and table view data source.

16
00:01:06,070 --> 00:01:07,470
Okay this is how I like to do it.

17
00:01:07,480 --> 00:01:12,880
I like to use an extension down at the bottom just to show exactly what type of extension I want to

18
00:01:12,880 --> 00:01:13,660
add to my goals.

19
00:01:13,660 --> 00:01:18,400
VC instead of conforming to it up here I like to conform to it in an extension that's just personal

20
00:01:18,400 --> 00:01:19,300
preference.

21
00:01:19,300 --> 00:01:22,930
And for some things it doesn't make sense but for you I table view delegate and data source.

22
00:01:22,930 --> 00:01:27,460
There's quite a bit of code that goes into it so it can be nice to separate it into its own extension.

23
00:01:27,460 --> 00:01:30,780
So we need to conform to three delegate methods.

24
00:01:30,790 --> 00:01:33,610
One is number of sections in table view.

25
00:01:33,610 --> 00:01:39,630
Another is number of rows in Section and the final one is cell Pharo at an X path.

26
00:01:39,700 --> 00:01:46,000
If you've used your table view you know these well now that we've extended and properly conformed to

27
00:01:46,000 --> 00:01:51,250
these three or these two methods in our view to load we can set up our table views delegate and data

28
00:01:51,250 --> 00:01:51,690
source.

29
00:01:51,700 --> 00:01:54,650
Those are super required in order for it to work.

30
00:01:54,670 --> 00:02:01,830
So go ahead and type table view delegate and set it to be self do the same thing for the datasource

31
00:02:03,270 --> 00:02:04,430
set it to be self.

32
00:02:04,510 --> 00:02:07,450
Ok that's how it knows what the delegate is and what its data sources.

33
00:02:07,450 --> 00:02:10,240
Otherwise it doesn't know where it's getting information from.

34
00:02:10,240 --> 00:02:13,610
So for the number of sections we're just going to return one.

35
00:02:13,730 --> 00:02:15,720
OK we don't need multiple sections in this app.

36
00:02:15,730 --> 00:02:21,780
We just need one big section of goals for the number of rows in section just for these static cells

37
00:02:21,790 --> 00:02:23,990
we're going to return 3.

38
00:02:24,240 --> 00:02:24,970
OK.

39
00:02:25,330 --> 00:02:31,050
And for our self-promote index path this is where we're actually going to create a cell.

40
00:02:31,090 --> 00:02:35,620
We're going to configure it and pass in some data and then we're going to go ahead and return that cell

41
00:02:35,620 --> 00:02:36,450
to the table view.

42
00:02:36,460 --> 00:02:42,390
So go ahead or return the cell rather to this function and then that will be used in the table view.

43
00:02:42,460 --> 00:02:46,560
I'm going to give you guys some more room to see here and let's create a cell.

44
00:02:46,600 --> 00:02:48,770
I'm going to use guard left because it's safer.

45
00:02:48,820 --> 00:02:54,790
And if we can't create a cell we're just going to return a blank table cell it's just a safe way to

46
00:02:54,790 --> 00:02:56,620
ensure that our app doesn't crash.

47
00:02:56,830 --> 00:03:03,950
So go ahead and type guard let cell equals and we're going to dequeue a reusable cell with identifier.

48
00:03:03,970 --> 00:03:06,780
You've already done this at this point in the course.

49
00:03:07,090 --> 00:03:09,580
But let's go ahead and let's let's do it now.

50
00:03:09,580 --> 00:03:18,250
Table View dequeue reusable cell with identifier like so and the identifier we already set to be goal

51
00:03:18,370 --> 00:03:20,970
cell with the capital G at the beginning.

52
00:03:20,980 --> 00:03:23,720
Now we are cueing a reusable cell.

53
00:03:23,740 --> 00:03:29,470
But the interesting thing is in order for this to work we actually need to cast it wups we actually

54
00:03:29,470 --> 00:03:35,710
need to cast it operationally as a goal cell so that it's of the proper type because otherwise it's

55
00:03:35,710 --> 00:03:37,630
just the table cell.

56
00:03:37,660 --> 00:03:39,720
So we are now casting this as a goal cell.

57
00:03:39,730 --> 00:03:49,750
But if that doesn't work else we're going to go ahead and return a UI table view cell just like so we're

58
00:03:49,750 --> 00:03:51,100
just returning a blank cell.

59
00:03:51,100 --> 00:03:56,770
OK so if we do get a cell though if we do have a value we can dequeue it.

60
00:03:56,770 --> 00:04:00,460
We're going to go ahead and call cell doc and fix your cell.

61
00:04:00,460 --> 00:04:00,880
All right.

62
00:04:00,880 --> 00:04:02,280
That's pretty cool.

63
00:04:02,290 --> 00:04:04,480
Now we're going to go ahead and give it a description.

64
00:04:04,480 --> 00:04:06,110
It's going to be a static description.

65
00:04:06,310 --> 00:04:11,010
Let's just say eat salad that's been my goal for this this app so far.

66
00:04:11,110 --> 00:04:13,270
How about twice a week.

67
00:04:13,590 --> 00:04:14,410
That looks good.

68
00:04:14,530 --> 00:04:21,940
Let's set a type of short term short term and the goal progress amount let's say that we want to eat

69
00:04:21,940 --> 00:04:23,990
it twice a week for food.

70
00:04:24,010 --> 00:04:29,800
Well this is short term so maybe it's just one week or two I guess is our goal because we're trying

71
00:04:29,800 --> 00:04:32,820
to to meet our goal of eating it twice a week.

72
00:04:32,830 --> 00:04:33,120
All right.

73
00:04:33,130 --> 00:04:37,970
So after the cell has been configured we're going to return the cell.

74
00:04:37,980 --> 00:04:38,870
All right.

75
00:04:38,890 --> 00:04:41,940
Now I don't know about you but I really want to go see if this works.

76
00:04:41,950 --> 00:04:47,600
Let's let's build and run it and let's see if if it shows up build and run.

77
00:04:47,620 --> 00:04:48,670
Here we go.

78
00:04:49,030 --> 00:04:56,280
Here's our simulator and nothing why is oh you know what guys our table use hidden.

79
00:04:56,290 --> 00:04:57,550
We have not yet shown it.

80
00:04:57,550 --> 00:05:03,970
So for now let's just go ahead and call table view is hidden is false because we're going to show and

81
00:05:03,970 --> 00:05:06,280
hide it later when we actually have data.

82
00:05:06,280 --> 00:05:11,450
We're going to show it but for now let's just go ahead and let's show it and then let's reload the data.

83
00:05:11,500 --> 00:05:12,480
OK.

84
00:05:12,490 --> 00:05:13,750
Very cool.

85
00:05:15,600 --> 00:05:16,040
Looks good.

86
00:05:16,050 --> 00:05:19,000
OK so there we go we have our goal.

87
00:05:19,020 --> 00:05:22,570
We have our number here for what we need to do to complete it.

88
00:05:22,770 --> 00:05:24,600
And yeah that's awesome.

89
00:05:24,600 --> 00:05:26,010
Our cells are showing up.

90
00:05:26,010 --> 00:05:29,640
This is wonderful but there's something we need to do.

91
00:05:29,880 --> 00:05:35,850
We need to change this type from something that is strongly like this and we're actually going to use

92
00:05:35,880 --> 00:05:43,180
an enum in K and an enum is a really easy way to deal with type related data.

93
00:05:43,260 --> 00:05:49,380
And so to do that let's go ahead and let's right click on the group click new file then click swift

94
00:05:49,380 --> 00:05:51,360
file and we're going to go ahead.

95
00:05:51,360 --> 00:05:56,140
I'm going to call this goal type that's going to be the name of the enim.

96
00:05:56,370 --> 00:06:02,370
OK press create and then inside this we're going to create an enum called Call type.

97
00:06:02,370 --> 00:06:09,390
So Type M K which has an enumerated type declaration according to swift and it's going to be called

98
00:06:09,620 --> 00:06:10,740
gult type.

99
00:06:10,740 --> 00:06:17,250
Now we're going to go ahead and create some brackets there and an ENM has what are called cases.

100
00:06:17,250 --> 00:06:22,770
So if we want to make a certain gold type we're going to give it the case long term we want it to be

101
00:06:22,770 --> 00:06:23,970
long term.

102
00:06:23,970 --> 00:06:28,350
We're also going to give it a case of short term OK because those are the two different gold types we

103
00:06:28,350 --> 00:06:29,360
can set.

104
00:06:29,370 --> 00:06:37,080
So go ahead and type that case long term like so and then go ahead and type case short term.

105
00:06:37,110 --> 00:06:40,000
If we build it we're just going to make sure everything's good.

106
00:06:40,110 --> 00:06:40,930
Very good.

107
00:06:41,190 --> 00:06:49,590
Now that's cool and all but if I go into those Fisi and if I pass in a gold type like so I can type

108
00:06:50,640 --> 00:07:00,180
goal type long term you know that's great but the issue is that there is not an explicit type that is

109
00:07:00,480 --> 00:07:05,940
used in gold type it's just long term it doesn't know if it's a string it doesn't know if it's an integer

110
00:07:05,970 --> 00:07:08,270
or a double or float or whatever.

111
00:07:08,310 --> 00:07:13,800
So we're actually going to go ahead and get rid of that and we're going to set this enumeration to have

112
00:07:13,800 --> 00:07:20,700
an explicit type and to do that we're going to go ahead and just inherit from string and on each of

113
00:07:20,700 --> 00:07:25,500
these cases we're going to set them to be equal to a string value like so.

114
00:07:25,500 --> 00:07:32,190
So go ahead and type long term for long term and set short term to be equal to short term.

115
00:07:32,190 --> 00:07:35,540
Now our numerator has an explicit type.

116
00:07:35,550 --> 00:07:40,740
And the reason we're doing this is because our X-C data model requires the gold type to come in as a

117
00:07:40,740 --> 00:07:41,160
string.

118
00:07:41,160 --> 00:07:44,650
We can't pass it a custom type the way that we're doing it.

119
00:07:44,850 --> 00:07:48,810
So what we're going to do is we're actually going to change our configure cell function.

120
00:07:48,970 --> 00:07:49,230
OK.

121
00:07:49,230 --> 00:07:52,720
Remember we use string and I said we would go back and change that.

122
00:07:52,920 --> 00:07:58,990
We're actually going to pass in gold type K but you'll notice we'll get an error here.

123
00:07:59,010 --> 00:08:03,120
Can't assign value of type gold type to type string.

124
00:08:03,120 --> 00:08:07,750
The reason for that is this is of type gold type but text is expecting a string.

125
00:08:07,800 --> 00:08:12,020
So to fix this all we need to do is to pull out the raw value.

126
00:08:12,420 --> 00:08:13,770
From our type.

127
00:08:13,770 --> 00:08:14,390
OK.

128
00:08:14,640 --> 00:08:21,090
The raw value is a string and we can pull that out from this because it is explicitly set to be string.

129
00:08:21,090 --> 00:08:26,020
All right so that's cool and all but now what we can do is for type.

130
00:08:26,040 --> 00:08:30,080
Let's go ahead and redo this so that you can actually see what it looks like from the beginning.

131
00:08:30,090 --> 00:08:35,100
Configure cell if I come in here and redo it you'll see now that it's asking for an instance of gold

132
00:08:35,100 --> 00:08:35,790
type.

133
00:08:35,790 --> 00:08:39,970
So the description is eat salad twice a week.

134
00:08:40,290 --> 00:08:42,370
The type we can just press dot.

135
00:08:42,390 --> 00:08:44,250
That's how you use an enumeration.

136
00:08:44,370 --> 00:08:53,640
And we can give it short term OK the progress amount we're going to set to be to maybe we have completed

137
00:08:54,240 --> 00:09:01,310
two of our salads for this week and then we are good to go we can now configure the cell properly.

138
00:09:01,440 --> 00:09:07,650
We can pass in a short term because the explicit value of this is short term a string.

139
00:09:07,950 --> 00:09:12,230
And when we configure the cell we pull out the raw value which is a string.

140
00:09:12,240 --> 00:09:16,950
So let's build and run this let's make sure that what we're doing is good to go and that we can properly

141
00:09:16,950 --> 00:09:21,030
pass in our numeration and it looks like it works.

142
00:09:21,040 --> 00:09:21,820
This is amazing.

143
00:09:21,820 --> 00:09:27,250
Short term comes through we passed in daat short term but it pulled out the explicit value from the

144
00:09:27,670 --> 00:09:30,010
raw value call when we pass it in.

145
00:09:30,010 --> 00:09:37,180
So superduper cool our table views working our goal type enumerator is properly passing an explicit

146
00:09:37,180 --> 00:09:42,280
string values and in the next video we're going to build out create gold Visi which will be presented

147
00:09:42,280 --> 00:09:44,160
when we click this button.

148
00:09:44,470 --> 00:09:50,710
Then it's going to allow us to start the process of creating what will pass in to an instance of an

149
00:09:50,850 --> 00:09:55,630
s managed object which will go into our core data model which is just so cool guys.

150
00:09:55,630 --> 00:09:56,810
I love this.

151
00:09:56,890 --> 00:09:57,940
Cordate is amazing.

152
00:09:57,940 --> 00:10:02,190
So let's go ahead and let's head over to the next video where we'll build out create gold Visi.
