Welcome back to class everyone Johnny B here with slopes dot com and in this lesson we are continuing
working on our comments.
VC we are just kind of laying the groundwork so that we can pull in common data once we get that added.
So in that last lesson we have created are you I in the main story board we got our table view and actually
I need to add some constraints on this table you need to go 0 0 0 and 0 had those four constraints.
There we go.
That looks better.
And then in our comments we see we have the beginnings of what we need to add for our table to work.
So when you were working with table use obviously we need our table view delegate and datasource let's
add those say Table View delegate and you table view data source.
There you go.
And then let's go ahead and set those and viewed it.
So to get to see Table View dot delegate is equal to self.
No not that self table view that data source is equal to self.
Okay.
And then we need to add a couple of methods that are required for these protocols.
Case So those are going to give a little bit space here to get this up to the middle and those are number
of rows in section now just return 0 and then
sell for row index path.
And here I'll just return you my table a view so generic for now.
Okay.
So jump into our main VC does Swift just kind of refresh how the how this works what we need is a an
array of items that we can add to our table view.
In the case of the main DC it was an array of thoughts.
Okay.
And so because of that we created a thought model and it had all of this stuff.
And then our main VC we were able to go through and look through those and dequeue sales based on that.
Okay.
So in our comments AVC we're going to be doing the same thing.
So we're going to need a new class but instead of us thought this is going to be a comment but it's
going to be very similar.
In fact it's going to be so similar that I'm actually going to copy and paste most of it just to say
some time when I say new file I say next.
And actually we can go back.
This can just be a swift file actually as a swift file.
Let's say next and we're going to call this comment.
So this is a model file for our comment.
All right then I'm going to open our hearts with the file.
And like I said this is going to be very similar.
So I'm actually just going to copy this whole thing here.
OK.
I'm going to copy it and paste it here.
After I do find the class a say class comment.
There you go.
I'm going to paste those things that I got from thought.
All right.
So just like thought we have some of the same things we have usually same time stamp and some text.
We're going to delete these three because we don't have any of that and I'm going to change this thought
text to comment text.
OK.
And then in our initialiser here I'm going to delete these three here.
I'm going to change comment text here to common text here and common text here.
And this is also going to be common text.
I'm going to delete the last three items in our initialiser and there we go.
Our parse data function is going to be also very similar.
So I'm going to need to import firebase and that looks good.
I'm actually going to just comment all of this out for now and we'll come back to that in a lesson or
two.
All right.
I'm going to save that up looks like it wants returns.
I want to comment out the entire function.
There we go.
I can save that and we'll come back to this function here in a lesson or two.
But for now this is all we need for our comment.
And just to run over this one more time.
We have private variables of username time stamp and the comment text.
Then we have our initialiser here using timestep in comment text and that's it pretty simple.
Just a simple class and it's initialiser and then we're going to jump back into our comments Visi and
let's go in and create a variable called comments and this is going to be equal to an array of comment
and we will initialize it to an empty array and then down here in our number of rows in S..
Now instead of returning 0 we can actually return comments that count.
And here in our cell for row function we can say if let.
So it's equal to table view.
And we're going to Q Celso the Q reuseable cell with identifier of string for index path.
And they didn't find we actually haven't said yet.
So we need to jump back into our storyboard select our comment cell here and in our attributes and Specter
said a reuse identifier we'll just say comment cell Kate going to copy that and jump back in the comments
of the C.
And that's what this identifier right here is.
So when I say comment sell for index path and the index path is index path that grow.
OK so if let's sell and we're going to cast it as a comment cell and then what are we going to do with
this so that we just created to what's going on here and it's path index path that we're just just index
path.
All right.
And so now what do we do with this cell we say cell and we need to add a function in our comments cell
to configure it.
So let's go and do that real quick.
So here in our comments cell we were going to create a function called configure cell just like we usually
do.
And we're going to pass into it.
And see here it looks like I missed a closing curly brace.
There we go.
Configure cell and we're going to pass into this a comment type comment and we're just going to set
these variables right here.
Right.
So user name is username.
Text that text is equal to going to say home and that is passed into it that username and then the comment
text that text is equal to comment dot comment text.
And then when you have a date here and let's go ahead and write the code for that.
We're going to need a form letter so this is just like what we did in our thought so here.
In fact I'm just going to copy this code that we have here and paste it in our comment.
So here and just modify it as needed.
Let's see here for a matter.
Time stamp.
So this should be comment time stamp and this should be calm and text that text equals time stamp.
I'm going to save that.
And that looks good.
And we're not using our awake from NIB at all so I'm just going to delete that.
And that was good.
All right let's jump back to our comments of PC-DOS Swift.
And now that we have our configure function we can say cell that to configure our cell and we're going
to pass into it.
The comment that corresponds to this index path Rowse when I say comments and we're going to grab out
of the array Commines index dot row and then we're going to return.
So that looks good.
And if for some reason we are not able to teach you a cell then we'll just return a generic table view
so.
All right.
And I think we're going to call this video good in the next lesson we are going to add our first comment
and learn about a new fire store technique that we haven't used yet called transactions.
All right.
So I hope you're excited for that and I'll see you in the next one.