This is a collection of handy View Controller Lifecycle Behaviors, useful for formalizing reusable bits of common lifecycle-dependent functionality.
Behaviors are implemented by consuming ViewController
s simply by leveraging the category method addBehaviors(_ behaviors: [ViewControllerLifecycleBehavior]
in viewDidLoad
:
override func viewDidLoad() {
super.viewDidLoad()
let behavior1 = MyBehavior()
let behavior2 = AnotherBehavior()
addBehaviors([behavior1, behavior2])
}
Default behaviors are behaviors that are automatically injected into all view controllers using method swizzling. This may be convenient for functionality akin to analytics screen tagging, for instance. Default behaviors are injected using:
let behavior = MyBehavior()
DefaultBehaviors(behaviors: [behavior]).inject()