In this tutorial I show the newest IOS10 Swift 3 version of my old Objective-C tutorial. We will create a Swift 3 Xcode 8 Single View Project with subclassed Custom Segue and Custom Unwind Segue. The customization will be a UIAnimation using NavigationController.
First Create new Swift Project, and add a second ViewController to your Storyboard. Subclass it (add new File named:SecondViewController, type: Cocoa Touch Class, language:swift, subclass:UIViewController), and set at storyboard the class of the ViewController "SecondViewController".
Don't forget, as a Swift project, you need to select at the Module Field your own Project name!
Add an UIButton to the first ViewController named "CustomSegue", and add another one to the SecondViewController, and named "CustomUnwindSegue".
Create a "Show" Segue from the "CustomSegue" button to the SecondViewController (ctrl+drag). Named:"CustomSegue".
Now your Project looks like this:
Now select the first ViewController, and embed NavigationController (Menu: Edit -->Embed in -->NavigationController).
In SecondViewCotnroller.swift create "colorstring" NSString object.
In ViewController.swift file create the prepareSegue method:
In SecondViewController.swift file set the backgroundColor purple, if the "colorstring" is "purple":
Now you can test it in simulator. If you see purple SecondViewController, everything's fine.
In ViewCotnroller.swift write an unwind IBAction, and set the backgroundColor for cyanColor:
In the Storyboard drag the SecondViewController's Button with ctrl to the Exit, and select the create unwind function.
If you click the CustomUnwindSegue button, and see the first ViewController with cyan backgroundColor, you can go forward for the customization.
3.1 Set custom kind of Segue, subclassed it and embed NavigationController in the first ViewController.
At the Inspector at the CustomSegue, select at Kind: "Custom". Now you have a warning, that says, you have to create a custom class, so do it. (Right click - > New File --> Cocoa Touch Class -->Language:Swift, Named:CustomSegue, subclass:UIStoryboardSegue).
And in the Inspector at the Class Field enter this new Class name.
If you have an error later, you should select your Project Name, so your Target at the Module Field. Maybe it will not appear, in that case you should open your storyboard as a Source Code and add it to your <connection> code as a customModule after your customClass. Example:
For using Custom Segue, you must to override perform function. There we can detect the Source View and the destination View. After that you can create an easy UIAnimation with the Views' positions.
Now you can test it, and see, that your SecondViewController comes from top instead of side.
Create a New Cocoa Touch File named: UnwindCustomSegue (subclass:UIStoryboardSegue, language:Swift). At Storyboard, add Custom Class name to your Unwind Segue:
And let the same source and destination Views and window hierarchy in CustomUnwindSegue class perform function. You can use the same UIAnimation too, just with another parameters:
Check the CustomUnwindSegue animation toot, it should disappear to top, and first ViewController should appear from bottom.