UIViewControllerRestoration protocol should be adopted by classes that act as "restoration classes” for view controllers during the state restoration process. The method in this protocol should be used to create the view controller, if it does not yet exist, or return an existing view controller object, if one does exist.
To use a class that adopts this protocol, you must assign that class to the
restorationClass property of one of your app’s view controllers.
viewControllerWithRestorationIdentifierPath(_:coder:) + viewControllerWithRestorationIdentifierPath:coder:Required
Asks the receiver to provide the view controller that corresponds to the specified identifier information.
An array of
NSStringobjects corresponding to the restoration identifiers of the desired view controller and all of its ancestors in the view controller hierarchy. The last value in the array is the restoration identifier of the desired view controller. Earlier entries represent the restoration identifiers of its ancestors.
The keyed archiver containing the app’s saved state information.
The view controller object to use or
nilif you do not want to restore this view controller now.
Your implementation of this method should create (or find) the corresponding view controller object and return it. If your restoration class determines that it does not make sense to display this view controller now, it may return
nilfrom this method to prevent that view controller (and its children) from being added to your interface during the restoration process.
You use the strings in the
identifierComponentsparameter to identify the view controller being requested. The view controllers in your app form a hierarchy. At the root of this hierarchy is the window’s root view controller, which itself may present or embed other view controllers. Those presented or embedded view controllers may themselves present and embed other view controllers. The result is a hierarchy of view controller relationships, with each presented or embedded view controller becoming a child of the view controller that presented or embedded it. The strings in the
identifierComponentsarray identify the path through this hierarchy from the root view controller to the desired view controller.
It is not always necessary to create a new view controller object in your implementation of this method. You can also return an existing view controller object that was created by another means. For example, if the view controller had already been loaded from a storyboard file, you would return that object rather than create a new one.
Your implementation of this method may use any data in the provided
coderto assist in the restoration process. However, you do not need to restore the entire state of the view controller at this point. During a later pass, view controllers that define a
decodeRestorableStateWithCoder:method are given a chance to restore their state from the same coder object.
Available in iOS 6.0 and later.