Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:35:24+00:00 2026-06-18T04:35:24+00:00

I need my app to remember which was the last UIViewController opened so when

  • 0

I need my app to remember which was the last UIViewController opened so when the app is loaded out of memory, I substitute a rootViewController property in the AppDelegate with one saved in NSUserDefaults:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = window;

    frontViewController = [[SGLoginScreenViewController alloc] init];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:frontViewController];

    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];
    return YES;
}

What I want to do is to put some code in the ViewDidLoad method of each ViewController and remember its name in NSUserDefaults to later use it in didFinishLaunchingWithOptions, something like this:

[[NSUserDefaults standardUserDefaults] setObject:self forKey:@"currentViewController"];
[[NSUserDefaults standardUserDefaults] synchronize]; 

The problem is, however, that XCode is giving me this warning:

*** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<SGMainScreenFirstTimeViewController: 0x8e1fea0>' of class 'SGMainScreenFirstTimeViewController'.  Note that dictionaries and arrays in property lists must also contain only property values.

Any ideas on how to implement this whole thing right? Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:35:25+00:00Added an answer on June 18, 2026 at 4:35 am

    You can only save in user defaults objects that can conform to the Key-Value coding (NSString, NSnumber, etc). Converting class to string and recreating class knowing class name would be the way to go for what you wish to achieve.
    This would be a good approach for saving in NSUserDefaults

    [[NSUserDefaults standardUserDefaults] setObject:NSStringFromClass([self class]); forKey:@"currentViewController"];
    [[NSUserDefaults standardUserDefaults] synchronize]; 
    

    And for loading back you recreate the class based on the saved string, as below:

    NSString *savedClassName = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentViewController"];
    UIViewController *controller = [(UIViewController *)NSClassFromString(savedClassName) alloc] init];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making an app which uses internet. I remember there was something developers had
My app need to target API level 7 and above, however I'd like to
My App need to save some data (around 100 double fields that is stored
my app need to show user scrollable menu bar under tab bar like fox
I need my app to be able access an third party API who limits
I need my app to create a dialog Seekbar. But I cannot make it
I need an app that sends an UDP packet to some network server and
I need my app to show as full screen. Now I know how to
I need to build app with user messages (dialogs). I've solved this problem by
In my app I need to download several images from a server. I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.