This is an example project which demonstrates the usage of CoreNavigation
's view controller data passing capabilities.
Medium posts:
Clone CoreNavigation
repo and:
$ cd Examples/PassingDataExample
$ pod install
- App has one view controller
ColorViewController
which:- can receive
UIColor
as a data - has color picker which triggers navigation to same view controller type and passes chosen color as data to the new instance
- can receive
View controller:
import UIKit
import CoreNavigation
import ChromaColorPicker
class ColorViewController: UIViewController {
...
}
// MARK: DataReceivable
extension ColorViewController: DataReceivable {
typealias DataType = UIColor
func didReceiveData(_ data: UIColor) {
view.backgroundColor = data
}
}
// MARK: ChromaColorPickerDelegate
extension ColorViewController: ChromaColorPickerDelegate {
func colorPickerDidChooseColor(_ colorPicker: ChromaColorPicker, color: UIColor) {
Navigate.push { $0
.to(Color())
.passData(color)
}
}
}
Destination:
import Foundation
import CoreNavigation
struct Color: Destination {
typealias ViewControllerType = ColorViewController
}