0

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

coernel
  • 79
  • 1
  • 9
  • Its viewController property is `restorationIdentifier.` It's listed on the Identity Inspector underneath where you set the controller's custom class. –  Aug 25 '15 at 00:07
  • Yes, but that is for UIView, not for UIViewController and it's subclasses. Anyway, I set them in code. Thank you =) – coernel Aug 25 '15 at 18:59
  • The one I told you about really is for the view controller. Inspect a view controller, then inspect a view. The properties may share the same name, but one pertains to the view controller; the other pertains to the view. –  Aug 25 '15 at 19:18
  • I am wondering because this is what I can find: https://www.evernote.com/l/AMnU4kgRWbxFp6rAONl7OGFDM4lSOpY5SzI – coernel Aug 26 '15 at 09:07
  • That screenshot is inspecting a view, so you see the view's properties, not a view controller's properties. If you have a top-level object for a view controller, you could inspect that. If not, you'll have to set its property programmatically. Here's [what a view controller's Identity Inspector pane looks like](http://i.stack.imgur.com/DUr8x.png). –  Aug 26 '15 at 15:25

1 Answers1

1

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