The course is part of this learning path
In this course, we're going to create an Instagram Clone and learn how to work with cloud servers using Firebase. By the end of this course, you will be well-equipped to build your own apps!
This course is designed for anyone who wants to:
- Learn about iOS development and coding
- Move into a career as an iOS developer
- Master Swift skills
To get the most out of this course, you should have some basic knowledge of iOS.
Hi. Within this lecture, we're going to take care of date problem so that we can actually save the current date that we are into to the firestoreDatabase so that we can retrieve all those values ordered by date later on.
So, if you come back here to firestorePost, right now we are just writing the value of date as a date, as a dummy value. Now, I'm going to delete this and I'm going to write FieldValue, okay. So, this one, FieldValue and we're going to say FieldValue.serverTimestamp. So, this is like a current timestamp that we can store to the firestoreDatabase and it gives us the year and the month, day, hour, minute, and seconds as well so that we can use this safely when we try to order everything by date. And in fact, there are a lot of other techniques to generate date and save them to the server as well. So, we can use swift techniques to generate date, to get date in a format that we want but I just don't want to complicate things. And if you use this FieldValue.serverTimestamp it will take the current date and save it to your firestore and we're going to test this and you will see what does it look like when we upload our first post after this. So, in here in the L section if this succeeds, what do we want to do? Remember,
we are just now sitting in the upload ViewController, of course we want to reset the comment and UI image and then go back to first ViewController. And in order to go to the feed ViewController, we're going to use the tabBarController. If you say selectedIndex then you can specify an index. For example, if you say 0, let me open our app from here. If you say 0, it will take you to the first index, if you say 1 it will take you to the upload, and if you say 2 it will take you to the settings. So, when you work with a tabBarController, you can change the index only by writing this one simple line of code, okay? And then we have to make sure tap to select image is placed into the image view and then comment text is reset. In order to do that, I'm going to go over here and say self.imageView.image is now a UIImage and we will just give it a name and I believe we have named this as select.png, right? And we can just come over here and say self.commentText.text is now an empty string. So, this will make everything right.
Here you go. Now we can test this. So, we're testing if we can actually provide the date value to our firestore and for some reason my Firebase is closed. So, let me go to console from here and we're going to have to click on and choose the current project that we're working on. So, in my case this is InstaClone Firebase. Now I can go to my database here. And in fact, we can see the changes in the database in real time if you just open it and leave it like this. You're going to see what I mean. So, let me choose a picture from here and let me write something like my favorite picture, okay? If you hit 'Upload' it will just upload the storage and take back the URL. And as you can see it took me to the feed and in the real time it added my data to here. So, here you go, we have the date here. Let me zoom in a little bit so you can see it better. So, this is the day, and the year, and the hour. So, we have everything up till the second. So, it works, okay?
And I believe we can test this one more time. We don't have to rerun this simulator because we are not changing anything. As you can see it is reset, because we have made it so, we have reset the comment text and we made image view in the way that we want and as you can see if we do it again, it just creates the post so we can see the information in here as well. So, that's good. That's working. So, we actually completed the process of uploading. Now We're getting the data, we're getting the image, likes, comments, and post owner. And I'm going to delete this one because we don't have any data in here. So, we only have two posts in which we all have date. And within the next lecture, we're going to get this information from the firestore so we want them to be consistent. So, if you have any other dummy values, tests, posts in here, make sure you delete everything and start from scratch. So, we want to add a feed in here basically a custom table view in which we can display all of this information to the user. We haven't done it yet. So, we're going to learn a new technique as well and it's a little bit long so we have to stop here and within the next lecture, you're going to see how to customize table view cells.
Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.