Welcome back to class ladies and gentleman joining me here with those slopes dot com.
And we are about to embark on the final stage of our Random app.
We've done a whole lot.
Up till this point in the previous two courses.
So if you have not taken both of those I would highly recommend going back and starting with the fire
store of course followed up with fire part two right because we're going to be building off of the app
that we built in those two courses.
All right.
And yes what are we going to do in this course.
Well if we check out our mockup that you have available in the assets for for this lesson then you will
see that we are going to be adding some more functionality.
So up until this point we've been able to create posts and add comments.
Now we are going to learn about how to delete our store documents and collections as well as learn some
more advanced fire store security rules.
All right so that's going to be the focus of this target topic.
And so you'll see here that we have this indicator here next to some of the posts and what this is is
this is a little menu that can pop up if it is a comment or a post that you wrote.
OK.
So if you did not write it right now J.B. is logged in.
And so J.B. wrote these posts and so the indicator is showing here.
But for Bela's posts it is not showing because we cannot alter her posts.
Right.
So you can only delete or in the case of comments you can see here that comments can delete or edit
the comment.
And over here we have a new view controller where we're able to actually edit comments.
So it's going to be pretty cool stuff.
So you're excited so let's jump right in.
So I mentioned that we have some assets available.
So let's go ahead and check those out.
We have a folder of assets and I couldn't really decide on how I wanted that little indicator to look.
So you got up you got several options you've got four different styles.
Some are thicker and in two different colors orange and the dark gray.
All right.
Just square and add those when open the assets and then drag all of those in and you'll be able to kind
of see the different styles for that button that you are able to pick for yourself.
So whichever style you are most inclined to pick go right ahead and let's see here what else do we have
in that folder.
We have the mock up that we were just looking at as well as the starter code.
If you haven't taken the previous two and it you just want to start right here I don't recommend it
but if you do or if you kind of just want to make sure that you are starting at the exact same point
as I am then you can use the starter code right here as well.
All right so now that we have our new assets in here and we've kind of talked a little bit about what
we want to do let's think about how that's going to work in code.
Okay.
So just coming back here again looking at this we want it so that we can know if a thought or a comment
is owned by the user.
So right now if we take a look at our thought and common models there's not really any way of knowing
that.
So we're going to have to do a little bit of modification here.
All right so each thought in each comment we need to add a new property that will hold the user's ID
at the time that it is created.
So let's go to an ad that will just go ahead and add it to both.
So let's start with thought here.
So when I say private set var and when I say user id and this is a string.
And when we initialize we are going to do as well from say user id type string.
And then we're going to say self-taught user ID is equal to user ID and that looks good.
Then on here in the Parus we're going to need to parse it out but we're going to need a new constant.
Someone create a new constant here and this is going to be a new field.
So when I say let user underscore ID equal user id go and jump back into thought and we'll say that
user id equal.
And that is data and the constant user ID as a string or else will just to empty string.
Right now we're going to need to adjust our constructor here for the thought.
So when I say user ID and that is user ID.
There we go.
Right.
So our class is all taken care of.
But now when we actually create this thought We need to modify that as well.
So here in the ad thought Visi lets see here down here where we say post button tappet we are going
to need to add the user id to the data that is saved to the document.
So Im just going to do a comma and say user lets see here underscore.
I am not sure why the autocomplete is not working but there we go.
And to get the user id we just check out our firebase instance and we say off of that current user you
ID.
And since that is an optional we will just provide an empty string and we are going to do the same thing
to our comment and output file.
Now having already gone through this process I also know that we are going to need the document ID in
the future so let's go ahead and add that as well.
So we're going to add two properties we're going to add the document ID which is of type string as well
as the
user id which is also a string.
All right then we're going to need to add those to the initialiser Yes we're going to say document ID
of type string and user id of type string that should be a colon there we go.
And then add them down here's when we say so that document is equal to document the self and user ID
is equal to user ID.
And then we're going to need to parse out those two new properties.
I'm going to say let document the equal document dot document ID so together document ID we just get
the document that we are looking through and access the document ID property.
OK.
And then we're going to say that user id equal data and the constant key user ID has a string else just
an empty string.
And then we do just our initialiser here.
So this is going to be a document ID is document ID and that user ID is the user id right so that is
taking care of our class is complete.
Now we need to go to where the comments are created.
So here in comments we see and let's see here add comment tapped her going to need to update our set
data right here.
So all right so we are going to be adding the user ID.
And again we just access that by off of the current user data.
You id instance is optional We will provide a default empty string.
All right.
That looks good.
So now when we save to our fire store database has to go and take a look at that our documents for our
thoughts and our comments will have the field for user ID.
Now if you're using the same database that you used in the previous two courses and you have a bunch
of testing here you may want to just delete all of your prior documents and start over so that your
new documents have this information.
To do that you can click right here and say delete all documents.
And that way you'll just be starting from a clean slate with all of your data all of your documents
having all of the data that it needs.
All right so now that are classes even have the capability of knowing which user they belong to.
Let's go ahead and add that image button.
Someone go into main storyboard and for our thoughts sell here I'm going to go ahead and drag in an
image.
You can I'm just going to drop that are right here.
Resize that.
And let's go ahead and set an image for it.
And like I said you can pick any of the four images that you like.
We have this one which has orange and it has a slightly thicker stroke on the Hondius circles.
We have that in dark.
We have that in and then we have one that is thinner stroke and that in dark as well.
I think I'm going to go with this one here.
And then I'm going to I just kind of put this up here and we're going to control and drag it to the
time stamp label and centered vertically and then we'll just set it to 14 from the right.
That looks pretty good to me.
All right there we go.
And now let's go ahead and add it to our thought.
So I'm going to hold option and click on thought cell to open it up in our assistant editor and we go
and I'm going to add this.
I yell it here.
That's when control and drag from there ends say options menu and say connect and then we'll close that
and we're going to do the same thing on our comments cell here.
So it's going to drag an image view and a resize that to about 30 by 30 is going to resize that here
30 by 30.
And then we're going to change the image too.
I'm going to choose Options image dark and then we're going to just drag that up here and zoom in here.
I'm going to close this bottom paint as well.
Want to control drag from the options image to the time stamp label and say center vertical and and
then we'll add a chilling space and that looks fine we'll say about 11 that looks good.
All right so now we have our project kind of set up we've modified our thought and comment classes.
We've added the options of menus to our comment and thought cells.
And in the next lesson we are going to work a little bit more in the code and logic adding some protocols
and delegates and yes we're going to be working on some cool stuff here so I'll see you in the next
one.