#2 iOS — Reinventing view controller navigation
Passing data between view controllers.
CoreNavigation extends UIKit with additional features and tools helping you handle navigation use cases in few lines of code.
We are gonna make a simple app with just one view controller containing a color picker.
- navigate to the new view controller of same type and pass
UIColorwhich will be assigned to view’s
ChromaColorPicker is used for the demo purpose.
Make view controller able to receive data by conforming
DataReceivable type has it’s associated type
DataType. This means a
Destination type can know about its view controller’s data type which opens a possibility to pass a concrete data from an outside world.
Destination (view controller wrapper)
Destination protocol has it’s associated type
ViewControllerType which is the
UIViewController type. This means destination type can know about its view controller type. In this particular case, a
Color destination is paired with
Detect color picker changes and navigate:
Destination type is optional and practically has no use in this use case but using it will give us an advantage in our next task where we’re going to extend current app with deep linking capabilities.