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 7990895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:08:13+00:00 2026-06-04T13:08:13+00:00

I am trying to find out how to save/store my values from NSDefaults so

  • 0

I am trying to find out how to save/store my values from NSDefaults so that when I exit the application they are stored in the Settings.bundle. This is what I am doing…

NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:@"M1", @"IDMissiles", 
                                                                    @"G2", @"IDGuns", 
                                                                    @"B3", @"IDBombs",
                                                                    @"KM", @"IDDistance", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:settings];

If I do the following, the values print out correctly from NSUserDefaults …

NSLog(@"IDMissiles: %@", [userDefaults stringForKey:@"IDMissiles"]);
NSLog(@"IDGuns    : %@", [userDefaults stringForKey:@"IDGuns"]);
NSLog(@"IDBombs   : %@", [userDefaults stringForKey:@"IDBombs"]);
NSLog(@"IDDistance: %@", [userDefaults stringForKey:@"IDDistance"]);

However … Each time I run the application the values in NSUserDefaults start off as (null), I was thinking that doing [[NSUserDefaults standardUserDefaults] synchronize]; would store the values for the next time I run the application, but no such luck.

  • 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-04T13:08:17+00:00Added an answer on June 4, 2026 at 1:08 pm

    One thing I discovered when working with the settings.bundle is that none of the values get initialized until you actually open the settings pane. You can have default values saved there, but they will return nil until you open the settings.

    I’m not sure if this happens when you try and save values there but never open the settings pane.

    If you are not using a settings pane, then you wouldn’t want to use the registerDefaults option.

    Try this instead.

    [[NSUserDefaults standardDefaults] setObject:@"M1" forKey:@"IDMissiles"];
    // set remaining values
    [[NSUserDefaults standardDefaults] synchronize]; // this really only needs to be called if you plan on accessing values right away, otherwise they are saved automatically after the next run loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent days trying to find out how to save or update a value
I am trying to find out how to upload a file from a web
I'm trying to find out if there's a Wikipedia API (I think it is
I'm trying to find out how to programmatically (I'm using C#) determine the name
I have been trying to find out why the following lines of code do
I am trying to find out the difficulty of implementing a queue system. I
I'm trying to find out weather I can do this or not. I have
What I'm trying to find out is whether there is some sort of equivalence
I am trying to find out if a given executable (or library) is compiled
I'm trying to find out whether a Socket is currently connected - according to

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.