[MUSIC] In this module, we're going to talk about using more of your controllers in an app. As you see in this current app, we have going, it's pretty nice, but it's all containing this one view controller. We do present some system view controllers, for example, the image picker, when you tap on this button and the system share sheet. But we don't have any other view controllers. So you can see that from our story board. It's pretty bare. And most apps, I mean for a photo editing app, this is okay. All the functionality can be obtained here. But in most apps, you're generally going to have more view controllers and more pages to go to. Maybe traverse through and navigate through. Or even have a tab bar of some sort. And that's all very common, so in this module we are going to cover different ways you can do that and in this lecture specifically we are going to introduce you to a very important concept in all this called [UKNOWN], so first, we are going to have to have another view controller in this app and say our app is going to have a social component and we actually are not going to Implement it. But say, we had another view controller over here. And just so it's not all blank, we want to give it a background color. So if you click under View, it will be this nice pinkish color. All right, so that's our associate view controller. And as you can see, now we have two view controllers in our story board. The only difference is there's a little arrow here. And this signals the initial view controller for the storyboard. And you always have to have one, and you can only have one. And it will be the first that's displayed if this is your, it's the review controller of this storyboard. So to transition between these two view controllers, I mean you've seen how to present the image and the in the past, and so you can also just instantiate this view controller in code. And then, present it. However, segues allow you to model this directly into storyboard in a very nice way using more arrows, and arrows are nice. So you can do this, by holding Control and dragging from one view controller, one scene to the next. You get this menu that gives you a few options as different kinds of, are ways you can transition. You can segway from this View Controller to the next. So, you have Show, Show Detail, Present Modally, Present as Popover, and again, we have Custom segways, where you overwrite an actual segway object, and do custom transitions, custom animations, anything you want, really. In this case, we're going to do Modally. Present Modally is, basically The same as when you did present View Controller in code, when you forward image picker and such. And so, this will have this View Controller slide up from the bottom. So you have this segue, but how can you trigger it? So in this case you can do it in code. But a very nice thing, another very nice thing about segues is that you can actually connect them to a button. So in order to do that, you're going to add a button to this bar. We're going to copy and paste the share button, and we're going to remove it's connection to our share function, and we're going to remove the image. And call it Social. All right, now instead of connecting the segue to a view controller, delete it, and we're going to click Control and drag from this button to isolation View Controller. And, again, choose present modally. And now when you press on the segue, you can see that the social button gets highlighted, and that means that it is connected to this button. So we're going to just build and run right now, immediately, and we're going to click on this brand new social button and we get our controller. Pretty convenient. Notice, like the system handled everything. It allocated this view controller and this view controller doesn't exist anywhere yet. It's just in the storyboard. It creates an instance of it, and then it presents it. You even saw that animation. That's very nice. So in the code, you can customize all of this. So, as you can. Imagine a lot of time when you do something like this, you want to customize this view controller. You might want to say, if it's social, you may want to pass over some user information or maybe even this photo, if you're going to save it there. But say, for example, in a social app like Facebook, when you press on a post, you're going to go to its details, you would want to customize the page with what you just tapped on. So you can do this all in code in the view controller object. And I'm just going to show you a few methods that are very useful, and the main one is called Prepare for Segue. And this method is called, right before it's presented. So the destination view controller, in this case our social controller, is already instantiated and all set up. And it will call prepare for segue first, before it does anything and passes you the segue object and the sender. And the sender being the button or whatever triggered the segue. And the segue object is interesting in that, it contains references to the destination controller in the source b controller which is in our case view controller. In through disc, you can then customize it. Also segues have identifiers in case you have, you can have multiple segues going from your one v controller to multiple usb controllers. And it's nice to give them identifiers. For example, PresentSocial. And with this identifier, you can also do something cool. And we're going to do this cool thing on a view controller, you can trigger a segue, you can perform a segue. So you can do, self.performSegueWithIdentifier. And if you pass in the identifier, it will perform the segue, as if you pressed the button and it will do all the same things and also call, prepareForSegue. So I'm just going to show you some typical implementation to prepare for seg. So here, since this gets called for any segue, the first thing you want to do is check which segue you're performing. In this case we only have one, but you can still check. So we can, we can use two things. We can check the destination controller's type for example, or we can use it's identifier. An identifier, since you said it yourself, is a pretty safe bet. So if we check the segues Identifier, and check if it's equal to, and it was PresentSocial. Then we can get the Then, we can get the view controller itself, the destination itself as an object. So we're going to let, we're going to. Unwrap it. It might not exist, but it usually should. Actually, it does exist. It's not an optional. You don't have to unwrap it. So you can directly create a new view controller. We're going to call it destination. Equals segue.destinationViewController. And the reason why you usually have to unwrap is, you'd like to cast it. In this case, it's a ViewController directly. But generally, you're not going to have an instance of a ViewController, you're going to have a subclass. Like so here you would do an, if let destination controller. You would cast it with an as, to whatever view controller you have, and here you destination controller all it's UI, before it's presented, and say it has a delegate. You can set that up here as well, and that is very, very useful. All right, that's it for this lecture. For all the other kinds of segues, they're used in different ways. Especially the show segue. And there's also an embed one that you can't do from here. And we're going to talk about those in the next few lectures in this course. Stay tuned.