SegueCoordinator
open class SegueCoordinator
Builds on top of the storyboard and encapsulates navigation logic. View controllers delegates navigation requests to it and SegueCoordinator performs all required transitions as well as data transfer. Typically you should use its subclasses instead.
-
Reference to the storyboard the SegueCoordinator work with.
Declaration
Swift
public let storyboard: UIStoryboard -
Root navigation controller that was passed into initializer of SegueCoordinator.
Declaration
Swift
public let rootNavigationController: UINavigationController
-
Typically, you should override this initializer and specify storyboard name.
Example:
init(navController: UINavigationController) { super.init(storyboardName: "Main", rootNavigationController: navController) }Declaration
Swift
public init(storyboardName: String, rootNavigationController: UINavigationController)Parameters
storyboardNameName of the storyboard the coordinator will work with.
rootNavigationControllerNavigation controller for displaying controllers created by coordinator.
-
Pops view controller from the stack of the current navigation controller.
Warning
If the top view controller doesn’t wrapped in navigation controller the pop action will do nothing.
Declaration
Swift
func pop(animated: Bool = true)Parameters
animatedSpecify true to animate the transition. Otherwise, specify false.
-
Dismiss current modal view controller.
Warning
If the top view controller doesn’t present modally the closeModal action will do nothing.
Declaration
Swift
func closeModal(animated: Bool = true, completion: (() -> Void)? = nil)Parameters
animatedSpecify true to animate the transition. Otherwise, specify false.
completionThe block to execute after the view controller is dismissed.
-
This method will make a transition to the farthest matching controller. It performs searching for the first view controller matching the specified type. Then it closes all modal view controllers above the found view controller’s stack and pops navigation stack to make the found view controller the top. In other words, the found view controller becomes the top and visible.
Declaration
Swift
func unwindToFirst<T>(type: T.Type, animated: Bool = true, completion: (() -> Void)? = nil) where T : UIViewControllerParameters
typeType of required view controller.
animatedspecify true if you want to animate the transition. Specify false otherwise.
completionThe block to execute after unwind transitions are finished.
-
This method will make a transition to the closest matching controller. It performs searching for the last view controller matching the specified type. Then it closes all modal view controllers above the found view controller’s stack and pops navigation stack to make the found view controller the top. In other words, the found view controller becomes the top and visible.
Declaration
Swift
func unwindToLast<T>(type: T.Type, animated: Bool = true, completion: (() -> Void)? = nil) where T : UIViewControllerParameters
typeType of required view controller.
animatedspecify true if you want to animate the transition. Specify false otherwise.
completionThe block to execute after unwind transitions are finished.
-
This method will make a transition to the farthest matching controller. It performs searching for the first view controller matching the specified predicate. Then it closes all modal view controllers above the found view controller’s stack and pops navigation stack to make the found view controller the top. In other words, the found view controller becomes the top and visible.
Declaration
Swift
func unwindToFirst(animated: Bool = true, where predicate: (UIViewController) -> Bool, completion: (() -> Void)? = nil)Parameters
animatedspecify true if you want to animate the transition. Specify false otherwise.
predicateSearching conditions. Returns true if the view controller passed in its argument fulfills conditions of the search. Returns false otherwise.
controllerController to check for the searching conditions.
completionThe block to execute after unwind transitions are finished.
-
This method will make a transition to the closest matching controller. It performs searching for the last view controller matching the specified predicate. Then it closes all modal view controllers above the found view controller’s stack and pops navigation stack to make the found view controller the top. In other words, the found view controller becomes the top and visible.
Declaration
Swift
func unwindToLast(animated: Bool = true, where predicate: (_ controller: UIViewController) -> Bool, completion: (() -> Void)? = nil)Parameters
animatedspecify true if you want to animate the transition. Specify false otherwise.
predicateSearching conditions. Returns true if the view controller passed in its argument fulfills conditions of the search. Returns false otherwise.
controllerController to check for the searching conditions.
completionThe block to execute after unwind transitions are finished.
-
Closes all modal view controllers above the specified view controller’s stack and pops navigation stack to make it the top. In other words, the specified view controller becomes the top and visible.
Declaration
Swift
func unwindToController(_ controller: UIViewController, animated: Bool = true, completion: (() -> Void)? = nil)Parameters
controllercontroller to navigate to
animatedspecify true if you want to animate the transition. Specify false otherwise.
completionThe block to execute after unwind transitions are finished.
-
Create initial view controller from storyboard.
Declaration
Swift
func instantiateInitial<T>(type: T.Type) -> T where T : UIViewControllerParameters
typeExpected type of view controller.
-
Create view controller from storyboard by identifier.
Declaration
Swift
func instantiate<T>(_ storyboardId: String, type: T.Type) -> T where T : UIViewControllerParameters
storyboardIdStoryboard ID of view controller specified with identity inspector in Interface Builder.
typeexpected Type of view controller.
-
Create the initial view controller from the storyboard and present it modally from the current navigation controller.
Declaration
Swift
func modalInitial<T>(type: T.Type, style: UIModalPresentationStyle, wrapInNavigationController: Bool = true, animated: Bool = true, prepareController: (_ controller: T) -> Void) where T : UIViewControllerParameters
typeExpected type of view controller.
styleModal presentation style.
wrapInNavigationControllerSpecify true if you want to wrap modal controller in it’s own navigation controller. Otherwise, specify false.
animatedSpecify true to animate the transition. Otherwise, specify false.
prepareControllerThe block to execute after controller will be created. Pass any data and dependencies into view controller here.
controllerCreated view controller
-
Create the view controller from the storyboard by identifier and present it modally from the current navigation controller.
Declaration
Swift
func modal<T>(_ storyboardId: String, type: T.Type, style: UIModalPresentationStyle, wrapInNavigationController: Bool = true, animated: Bool = true, prepareController: (_ controller: T) -> Void) where T : UIViewControllerParameters
storyboardIdStoryboard ID of view controller specified with identity inspector in Interface Builder.
typeExpected type of view controller.
styleModal presentation style.
wrapInNavigationControllerSpecify true if you want to wrap modal controller in it’s own navigation controller. Otherwise, specify false.
animatedSpecify true to animate the transition. Otherwise, specify false.
prepareControllerThe block to execute after controller will be created. Pass any data and dependencies into view controller here.
controllerCreated view controller
-
Present controller modally from the current navigation controller.
Declaration
Swift
func modalController<T>(_ controller: T, style: UIModalPresentationStyle, wrapInNavigationController: Bool = true, animated: Bool = true, prepareController: (_ controller: T) -> Void) where T : UIViewControllerParameters
controllerController to be presented.
styleModal presentation style.
wrapInNavigationControllerSpecify true if you want to wrap modal controller in it’s own navigation controller. Otherwise, specify false.
animatedSpecify true to animate the transition. Otherwise, specify false.
prepareControllerThe block to execute before controller will be presented. Pass any data and dependencies into view controller here.
controllerController to be presented.
-
Create the initial view controller from the storyboard and push it to the stack of the current navigation controller.
Warning
If the top view controller doesn’t wrapped in navigation controller the push action will do nothing.
Declaration
Swift
func pushInitial<T>(type: T.Type, animated: Bool = true, prepareController: (_ controller: T) -> Void) where T : UIViewControllerParameters
typeExpected type of view controller.
animatedSpecify true to animate the transition. Otherwise, specify false.
prepareControllerThe block to execute after controller will be created. Pass any data and dependencies into view controller here.
controllerCreated view controller
-
Create the view controller from the storyboard by identifier and push it to the stack of the current navigation controller.
Warning
If the top view controller doesn’t wrapped in navigation controller the push action will do nothing.
Declaration
Swift
func push<T>(_ storyboardId: String, type: T.Type, animated: Bool = true, prepareController: (T) -> Void) where T : UIViewControllerParameters
storyboardIdStoryboard ID of view controller specified with identity inspector in Interface Builder.
typeExpected type of view controller.
animatedSpecify true to animate the transition. Otherwise, specify false.
prepareControllerThe block to execute after controller will be created. Pass any data and dependencies into view controller here.
controllerCreated view controller
-
Push view controller to the stack of the current navigation controller.
Warning
If the top view controller doesn’t wrapped in navigation controller the push action will do nothing.
Declaration
Swift
func pushController<T>(_ controller: T, animated: Bool = true, prepareController: (_ controller: T) -> Void) where T : UIViewControllerParameters
controllerController to be presented.
animatedSpecify true to animate the transition. Otherwise, specify false.
prepareControllerThe block to execute before controller will be presented. Pass any data and dependencies into view controller here.
controllerController to be presented.
-
This method will search the controller by its type. Search for view controller is starting on the navigation stack of the root navigation controller. Then the search continues on the navigation stack of the presented view controller and so on. This method will return the first view controller that will fulfill the conditions of the search. In other words, it returns the farthest to the current view controller in the navigation stack.
Declaration
Swift
func findFirst<T>(type: T.Type) -> T? where T : UIViewControllerParameters
typeType of required view controller.
Return Value
view controller if it was found, nil otherwise.
-
This method will search the controller with custom conditions declared in the predicate. Search for view controller is starting on the navigation stack of the root navigation controller. Then the search continues on the navigation stack of the presented view controller and so on. This method will return the first view controller that will fulfill the conditions of the search. In other words, it returns the farthest to the current view controller in the navigation stack.
Declaration
Swift
func findFirst(where predicate: (_ controller: UIViewController) -> Bool) -> UIViewController?Parameters
predicateSearching conditions. Returns true if the view controller passed in its argument fulfills conditions of the search. Returns false otherwise.
controllerController to check for the searching conditions.
Return Value
view controller if it was found, nil otherwise.
-
This method will search the controller by its type. Search for view controller starting on the navigation stack of the root navigation controller. Search for view controller is starting on the navigation stack of the root navigation controller. Then the search continues on the navigation stack of the presented view controller and so on. This method will return the last view controller that will fulfill the conditions of the search. In other words, it returns the nearest to the current view controller in the navigation stack.
Declaration
Swift
func findLast<T>(type: T.Type) -> T? where T : UIViewControllerParameters
typeType of required view controller.
Return Value
view controller if it was found, nil otherwise.
-
This method will search the controller with custom conditions declared in the predicate. Search for view controller is starting on the navigation stack of the root navigation controller. Then the search continues on the navigation stack of the presented view controller and so on. This method will return the last view controller that will fulfill the conditions of the search. In other words, it returns the nearest to the current view controller in the navigation stack.
Declaration
Swift
func findLast(where predicate: (_ controller: UIViewController) -> Bool) -> UIViewController?Parameters
predicateSearching conditions. Returns true if the view controller passed in its argument fulfills conditions of the search. Returns false otherwise.
controllerController to check for the searching conditions.
Return Value
view controller if it was found, nil otherwise.
-
Perform segue from currently presented view controller
Warning
If you override prepareForSegue method, be sure to call super.prepareForSegue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { super.prepare(for: segue, sender: sender) }Declaration
Swift
func segue<T: UIViewController>(_ segueId: String, type: T.Type, prepareController: @escaping (_ controller: T) -> Void)Parameters
segueIdSegue Identifier specified with Attributes Inspector in Interface Builder
typeExpected type of destination view controller.
prepareControllerThe block to execute before controller will be presented. This is prepareForSegue replacement. Pass any data and dependencies into view controller here.
controllerController to be presented.
-
Create the initial view controller from the storyboard and make it the root of the rop navigation controller. All other presented controllers will be removed from navigation stack.
Warning
If the top view controller doesn’t wrapped in navigation controller the set action will do nothing.
Declaration
Swift
func setInitial<T>(type: T.Type, prepareController: (_ controller: T) -> Void) where T : UIViewControllerParameters
typeExpected type of view controller.
prepareControllerThe block to execute after controller will be created. Pass any data and dependencies into view controller here.
controllerCreated view controller
-
Create the view controller from the storyboard by identifier and make it the root of the top navigation controller. All other presented controllers will be removed from navigation stack.
Warning
If the top view controller doesn’t wrapped in navigation controller the set action will do nothing.
Declaration
Swift
func set<T>(_ storyboardId: String, type: T.Type, prepareController: (_ controller: T) -> Void) where T : UIViewControllerParameters
storyboardIdStoryboard ID of view controller specified with identity inspector in Interface Builder.
typeExpected type of view controller.
prepareControllerThe block to execute after controller will be created. Pass any data and dependencies into view controller here.
controllerCreated view controller
-
Make view controller the root of the top navigation controller. All other presented controllers will be removed from navigation stack.
Warning
If the top view controller doesn’t wrapped in navigation controller the set action will do nothing.
Declaration
Swift
func setController<T>(_ controller: T, prepareController: (_ controller: T) -> Void) where T : UIViewControllerParameters
controllerController to be presented
prepareControllerThe block to execute before controller will be presented. Pass any data and dependencies into view controller here.
controllerController to be presented
-
Returns top view controller.
Declaration
Swift
var topController: UIViewController { get } -
Returns navigation controller of top view controller if it exists. Returns nil otherwise.
Declaration
Swift
var topNavigationController: UINavigationController? { get }
SegueCoordinator Class Reference