iOS State Preservation in XCode 6

96 views Asked by At

I would like to preserve my application's state in XCode 6 and iOS 8. However, all the information I can find refers to storyboards and restoration identifiers, but I am not using storyboards.

I am sure I could make sense of all these would it not be for one major thing: I can't seem to find the field for the restoration ID for View Controllers in Xcode 6. I have found the ones for views, but every tutorial makes it clear that I have to make sure to tag the controller, not the view!

Any help is highly appreciated :)

Thx in advance

1

There are 1 answers

0
AudioBubble On BEST ANSWER

restorationIdentifier is a view controller property as well as a view property.

From the View Controller Class Reference documentation:

restorationIdentifier The identifier that determines whether the view controller supports state restoration.

This property indicates whether the view controller and its contents should be preserved and is used to identify the view controller during the restoration process. The value of this property is nil by default, which indicates that the view controller should not be saved. Assigning a string object to the property lets the system know that the view controller should be saved. In addition, the contents of the string are your way to identify the purpose of the view controller.

State restoration is hierarchical in nature. As I'm sure you know, if you don't set the view controller's restorationIdentifier property, its view will not be saved, even if its view's restorationIdentifier property is set.

Update:

You can programmatically set your view controller's restorationIdentifier when you initialize it:

- (instancetype)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle
{
    self = [super initWithNibName:nibName bundle:bundle];
    if(self)
    {
        self.restorationIdentifier = @"MyViewControllerID";
    }
}

Since you're not using Storyboards, you can't inspect your view controller's properties. This is where the view controller's restorationIdentifier property is displayed.

Identity Inspector screenshot for a view controller