Everybody this is Caleb with Debb sloped dotcom.
And in this video we're going to set up our UI table view to show static data.
OK we're going to just make sure our cells are working.
Make sure we're good to go with configuring the cells we're also going to set up our table view which
is also cool I guess.
And we're also going to create an income so that we can properly display the goals type short term versus
long term.
So pull open that X code project and in the last video we set up our core data entity.
But for now we're going to go into that goals.
VC Okay.
And we're going to set up our table view so that we can actually use it.
Magine that we might well actually use our table view so down beneath our class outside of the class
we're going to create an extension of Goles.
VC so type extension goes.
VC and we're going to conform to you Table View delegate and table view data source.
Okay this is how I like to do it.
I like to use an extension down at the bottom just to show exactly what type of extension I want to
add to my goals.
VC instead of conforming to it up here I like to conform to it in an extension that's just personal
preference.
And for some things it doesn't make sense but for you I table view delegate and data source.
There's quite a bit of code that goes into it so it can be nice to separate it into its own extension.
So we need to conform to three delegate methods.
One is number of sections in table view.
Another is number of rows in Section and the final one is cell Pharo at an X path.
If you've used your table view you know these well now that we've extended and properly conformed to
these three or these two methods in our view to load we can set up our table views delegate and data
source.
Those are super required in order for it to work.
So go ahead and type table view delegate and set it to be self do the same thing for the datasource
set it to be self.
Ok that's how it knows what the delegate is and what its data sources.
Otherwise it doesn't know where it's getting information from.
So for the number of sections we're just going to return one.
OK we don't need multiple sections in this app.
We just need one big section of goals for the number of rows in section just for these static cells
we're going to return 3.
OK.
And for our self-promote index path this is where we're actually going to create a cell.
We're going to configure it and pass in some data and then we're going to go ahead and return that cell
to the table view.
So go ahead or return the cell rather to this function and then that will be used in the table view.
I'm going to give you guys some more room to see here and let's create a cell.
I'm going to use guard left because it's safer.
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
ensure that our app doesn't crash.
So go ahead and type guard let cell equals and we're going to dequeue a reusable cell with identifier.
You've already done this at this point in the course.
But let's go ahead and let's let's do it now.
Table View dequeue reusable cell with identifier like so and the identifier we already set to be goal
cell with the capital G at the beginning.
Now we are cueing a reusable cell.
But the interesting thing is in order for this to work we actually need to cast it wups we actually
need to cast it operationally as a goal cell so that it's of the proper type because otherwise it's
just the table cell.
So we are now casting this as a goal cell.
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
just returning a blank cell.
OK so if we do get a cell though if we do have a value we can dequeue it.
We're going to go ahead and call cell doc and fix your cell.
All right.
That's pretty cool.
Now we're going to go ahead and give it a description.
It's going to be a static description.
Let's just say eat salad that's been my goal for this this app so far.
How about twice a week.
That looks good.
Let's set a type of short term short term and the goal progress amount let's say that we want to eat
it twice a week for food.
Well this is short term so maybe it's just one week or two I guess is our goal because we're trying
to to meet our goal of eating it twice a week.
All right.
So after the cell has been configured we're going to return the cell.
All right.
Now I don't know about you but I really want to go see if this works.
Let's let's build and run it and let's see if if it shows up build and run.
Here we go.
Here's our simulator and nothing why is oh you know what guys our table use hidden.
We have not yet shown it.
So for now let's just go ahead and call table view is hidden is false because we're going to show and
hide it later when we actually have data.
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.
OK.
Very cool.
Looks good.
OK so there we go we have our goal.
We have our number here for what we need to do to complete it.
And yeah that's awesome.
Our cells are showing up.
This is wonderful but there's something we need to do.
We need to change this type from something that is strongly like this and we're actually going to use
an enum in K and an enum is a really easy way to deal with type related data.
And so to do that let's go ahead and let's right click on the group click new file then click swift
file and we're going to go ahead.
I'm going to call this goal type that's going to be the name of the enim.
OK press create and then inside this we're going to create an enum called Call type.
So Type M K which has an enumerated type declaration according to swift and it's going to be called
gult type.
Now we're going to go ahead and create some brackets there and an ENM has what are called cases.
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
long term.
We're also going to give it a case of short term OK because those are the two different gold types we
can set.
So go ahead and type that case long term like so and then go ahead and type case short term.
If we build it we're just going to make sure everything's good.
Very good.
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
goal type long term you know that's great but the issue is that there is not an explicit type that is
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
or a double or float or whatever.
So we're actually going to go ahead and get rid of that and we're going to set this enumeration to have
an explicit type and to do that we're going to go ahead and just inherit from string and on each of
these cases we're going to set them to be equal to a string value like so.
So go ahead and type long term for long term and set short term to be equal to short term.
Now our numerator has an explicit type.
And the reason we're doing this is because our X-C data model requires the gold type to come in as a
string.
We can't pass it a custom type the way that we're doing it.
So what we're going to do is we're actually going to change our configure cell function.
OK.
Remember we use string and I said we would go back and change that.
We're actually going to pass in gold type K but you'll notice we'll get an error here.
Can't assign value of type gold type to type string.
The reason for that is this is of type gold type but text is expecting a string.
So to fix this all we need to do is to pull out the raw value.
From our type.
OK.
The raw value is a string and we can pull that out from this because it is explicitly set to be string.
All right so that's cool and all but now what we can do is for type.
Let's go ahead and redo this so that you can actually see what it looks like from the beginning.
Configure cell if I come in here and redo it you'll see now that it's asking for an instance of gold
type.
So the description is eat salad twice a week.
The type we can just press dot.
That's how you use an enumeration.
And we can give it short term OK the progress amount we're going to set to be to maybe we have completed
two of our salads for this week and then we are good to go we can now configure the cell properly.
We can pass in a short term because the explicit value of this is short term a string.
And when we configure the cell we pull out the raw value which is a string.
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
pass in our numeration and it looks like it works.
This is amazing.
Short term comes through we passed in daat short term but it pulled out the explicit value from the
raw value call when we pass it in.
So superduper cool our table views working our goal type enumerator is properly passing an explicit
string values and in the next video we're going to build out create gold Visi which will be presented
when we click this button.
Then it's going to allow us to start the process of creating what will pass in to an instance of an
s managed object which will go into our core data model which is just so cool guys.
I love this.
Cordate is amazing.
So let's go ahead and let's head over to the next video where we'll build out create gold Visi.