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!
Intended Audience
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
Prerequisites
To get the most out of this course, you should have some basic knowledge of iOS.
Hi. Within this lecture, we're going to add a new view controller to our tab bar because we have to have a logout functionality as well and we're going to connect these view controllers to a Cocoa Touch Class. So far we have our feed view controller and upload view controller, but we don't have their Cocoa Touch Classes and in addition to that, we're going to have to have a third Tab Bar view controller as well. So, let me open the library and bring in one view controller. So, this is going to be a regular view controller so that you can drag and drop to anywhere in your storyboard. So, let me take this to the below and align them and then we're going to have to have a segue from our tab bar view controller, tab bar controller I mean to the new view controller. And in here don't select show segue because that's not we want. So, what do we want? In order to understand that let me click one of these segues that connects tab bar controller to our view controllers. If you go to properties, you will see that this is a relationship segue. So, we haven't seen it before. So, relationship segue actually creates a relationship between a tab bar controller and the view controller connecting to it. So, let me do it one more time and select relationship segue. So now, as you can see this is connected and we see the third item here as well. So, if I go to item here, I can change the title as I want like as settings view controller and for the icon of course we can go for S icon here as we did before. So, let me see where is the S icon, I cannot seem to find it, yeah here. I can find it s.circle. That's what I want. And now if I zoom in you will see that settings is here with an S Icon. So, this is perfect. This is what I wanted. But, now I have to create the Cocoa Touch Classes as well. So, let me click here and right click and say New File. Of course, we're going to go for Cocoa Touch Class. And this is going to be a UI view controller. So, the first thing I'm going to call feed view controller. So, this will be my view controller, feed view controller is Cocoa Touch Class. I'm going to say 'Next' and create in my InstaCloneFirebase project. And here we go, we have our feed view controller. Let's do the second one as well. Let's add another Cocoa Touch Class. And this time I'm going to call this UploadViewController. So, this will be the upload view controller and say Create. And for the third time I'm going to go and do the same thing, Cocoa Touch Class and this time I'm going to call this SettingsViewController. And in fact in the SettingsViewController we were only going to have the logout functionality but I'm doing this for an example. So, I believe that's okay. So, let me put all of this in the upper sites so that we can see all view controllers in one place. And the next thing I'm going to go to my storyboard to open it as a source. So, remember this, I have this bug when I add a new view controller, my application fails. My application crashes if I don't change the values from this source. If you don't come across this kind of a bug in your X code, then just don't do this step. But in case you have, in case you experience this problem, I'm showing you how to do that. And again, if you don't come across this problem, if you open your app without crashing it when you add a new view controller, just don't do it. So here, as you can see my regular old view controller, I have five attributes, like custom class, custom module, custom module provider. But, in the other view controllers they are added by me manually, I don't have those items. So, I have to copy and paste this custom class, custom module and custom module provider so that I won't get an interface failed error when I run this app. So, let me copy this and go back to the feed view controller for example and paste it in here. Again, if you don't have this problem then just watch and see how this is getting the result, but don't apply it, because in the XML, we are seeing an XML code right now it's likely to make a mistake. I'm copying and pasting the view controller missing attributes to all view controllers so that I can resolve this bug. And we have seen this before. So, I'm not going to go into the details. And I'm going to go back to interface builder. So, this is where you can continue if you don't have this problem in your X code. So, right now in order to see if it's working, I have to define some variables here. So, let me create my button in my settings view controller. So, let me make this a little bit bigger and change the name to logout. I'm going to connect this logout button to my settings view controller Cocoa Touch Class. In order to that I'm going to select settings and come to this identity inspector and this is not going to be a view controller but it's going to be a settings view controller, and it doesn't show up here. So, I suspect there's something going on still even though we have corrected everything. And if you click on this little button it will take us to the settings view controller. At least it seems to be working when we write it manually but I still suspect there is something wrong. So, let me write UploadViewController here manually. Okay, that's okay. And let's go to feed view controller identity inspector and let's say that this is feed view controller. So, that's cool. I believe we are ready to connect this logout button to the settings view controller Cocoa Touch Class. So, open a new assistant editor, and in here drag and drop the logout button with control and define it as an action and say logoutClicked. It seems fine, it seems to be working. So, we're going to test this, okay? As you can see this is now connected to settings view controller and I believe we are okay. So, let me give some constraints to the logout button as well. And we're done actually. So, in the logoutClicked, I'm just going to perform a segue for right now. Later on we're going to have to implement the log out function as well. But, I don't have this segue, right? Because I didn't create any segue between settings view controller and our initial view controller. So, let's do that. Let's drag and drop from settings to our view controller, sign in view controller and say show. And when I say show it's displaying this as a pop version, I'm going to change this to be Present Modally. So, let me choose the segue. So, Present Modally, and again in here, I'm going to go for full screen. So, it makes everything right and I'm going to say that this is toViewController. So, here we go. We are ready to test this perform segue. So, let me go to toViewController in here and sender will be nil. So, let's test to see if everything seems to be all right because we have changed the XML code. Even though if you didn't do it, you have to test this and see if this works because we added a new tab bar controller. So, let's see the initial view controller. Yes, that's good, and then I hit sign in, it stucks. It gets stucks. And I believe we crash the application for some reason. Let's wait for the error message. And here we don't have any error message but we see the black screen. And if you go to the logs as you can see it doesn't see the image view, the settings view controller, all the other view controllers that we have connected so far. So, this is the bug that I was talking about and we corrected it in the source code, but, I believe we have to do it again. So, let me open the source code. And if you don't have this problem, just don't bother with it. I'm not cutting this on purpose because if you come across you have to know how to solve this. This is not specific to iOS stored in this has been going on for years. I don't know why it couldn't figure it out yet. But, we sometimes get this bug in X code. So, as you can see in the view controller, we have this custom class, custom module and custom module provider. So, let me look below. We don't have anything else. So, let me copy this custom module and custom module provider because as you can see in the view controller, we are missing that. iIn the other view controllers, we are missing that. For example, in the feed view controller, we don't have that so I'm going to paste it in. And in the settings view controller, we don't have them as well as you can see, and in the upload view controller, we don't have them at all. So, let me paste it all. So, let me save this and let me go to Interface Builder one more time. And we're going to have to test this one more time. But before we do that, before you test this, before you run this in your simulator, make sure that before you hit the sign in button, go to your tab bar controller. This one, I mean not the view controllers but the actual tab bar controller. After you copy and paste XMLs, this class can get confused. In the identity inspector make sure the class is nothing. It shouldn't be view controller or like this feed view controller. If you see any value in the tab bar controller class just delete it. As you can see all other view controllers are in place and this should be empty. So, if you see any value, just delete it, hit Enter and then run your simulator one more time to make sure everything seemed to be in place. So, let me open my simulator and click on sign in. And as you see now it's okay, in the upload and feed, we don't see anything, but if we go to settings, we see the logout button and if I click on it, here you go, I'm in the signing view controller. And if I click on it again, I can go to my feed view controller. And as I explained before, I could have easily just paused the video and fix the bugs myself without showing you guys. But, maybe you come across this kind of problem right now or maybe you will in the future so you will have to know how to fix those problems. So, apologies for taking too long for adding just one view controller to our tab bar controller, but that is just what we had to do in order to learn this. So, we're going to stop here and within the next lecture we're going to see how to create users.
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.