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

  • Home
  • SEARCH
  • 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 6254355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:09:57+00:00 2026-05-24T14:09:57+00:00

I need to store a numeric parameter in NSUserDefault, this parameter must be as

  • 0

I need to store a numeric parameter in NSUserDefault, this parameter must be as default 1
So i write this code :

NSNumber *one = [NSNumber numberWithInt:100];    
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                      one,@"my-param",
                      nil];

[def registerDefaults:dict];

This parameter has a bind over a checkbox in IB so i can check that it’s correctly set and when i start my app i see checkbox with state “on”.

On the other side i must check this value programmatically so… i do something like :

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger my_param = [defaults integerForKey:@"my-param"];

I excepted that since the value is not set by the user this function return value that i set as default (in my case “1”) but with my surprise i found that if value has never been set by user it returns 0 … as you can understand this’s terrible 😛 because now i can’t understand if this “0” is obtained by user choice of this’s a consequence of a non-set value… how can i write code to manage this situation ?

  • 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-05-24T14:09:58+00:00Added an answer on May 24, 2026 at 2:09 pm

    To store the numeric values in NSUserDefaults you can simply directly use as follows:

    To set the integer Value in NSUserDefault use as follows below:

    NSInteger lInteger = 10; 
    
    [[NSUserDefaults standardUserDefaults] setInteger:lInteger forKey:@"integerkey"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    

    And to use that NSInteger value anywhere in your project use as below:

    NSInteger linteger = [[NSUserDefaults standardUserDefaults] integerForKey:@”integerkey”];

    And i didnt understand your question exactly, but anyhow i think this above code may help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Amazon's SimpleDB stores values as strings, and I need to store numeric values so
I need to store data in a grid like this: {0,1,2,3} {4,5,6,7} {8,9,10,11} {12,13,14,15}
I need to store products for an e-commerce solution in a database. Each product
I need to store phone numbers in a table. Please suggest which datatype should
I need to store app specific configuration in rails. But it has to be:
I need to store user entered changes to a particular table, but not show
I need to store some sensitive data by encrypting it with atleast 128 bit
I need to store items with a calendar date (just the day, no time)
I need to store some simple properties in a file and access them from
I need to store a list of key value pairs of (integer, boolean) in

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.