A little bit late invention to do unwind operations for UIKit developers that does not use storyboards. With this library, now you are able to unwind operations even with programmatic UI development approach(with UIKit).
Supported Containers
-
UINavigationController -
UITabbarController -
UIPageViewController -
UISplitViewController -
Your Custom Containers
Currently It is just usable via SPM. There is no future plan for add support for other package managers
https://github.com/ekoll/UIKit-Unwinder
In your target view controller create an unwind point method. Your unwind method must be @objc method.
class MyCustomViewController: UIViewController {
// Content of your ViewController...
@objc func unwindToMe() {
// Your unwind logic
}
}and call Unwinder from your unwind source
Unwinder.unwind(from: myCurrentViewController, target: #selector(MyCustomViewController.unwindToMe))You can also pass one parameter via this unwind operation
Just add your parameter to your unwind point method
@objc func unwindToMe(_ parameter: Any) {
// You may need binding here
guard let parameter = parameter as? MyCustomType else { return }
// Your unwind logic
}and send corresponding value for your parameter
Unwinder.unwind(
from: myCurrentViewController,
target: #selector(MyCustomViewController.unwindToMe),
parameter: MyCustomType()
)If you use a custom container mechanism to present your ViewControllers inside (like UINavigationController or UITabbarController) you must implement these two methods to manage unwind operation in your container
You should finds the target ViewController of unwind operation in its child ViewController(s) and return. Maybe your container can be the target, so it can return itself when needed
You should manage transition operation from current presenting ViewController to target ViewController in here. All the transitions between these screens in your container is managed here