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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:54:25+00:00 2026-05-21T02:54:25+00:00

I need to pre-populate and save an array in NSUserDefaults so that downstream methods

  • 0

I need to pre-populate and save an array in NSUserDefaults so that downstream methods can read and write to ten values stored there. I’ve constructed this workable solution, but is there a better way of doing this?

Any insight is appreciated!
lq

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *myArray = [[NSMutableArray alloc] init];

// Set the array with ten Zero Value placeholders

for (NSUInteger i = 0; i < 10; ++i) {                                               
    [myArray addObject:[NSNumber numberWithInt:0]];
}

[userDefaults setObject:myArray forKey:@"someKeyName"];
[myArray release];

Later methods call this array like this:

- (void)doSomethingUseful {

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    NSMutableArray *someUsefulArray = [[NSMutableArray alloc] initWithArray:[userDefaults objectForKey:@"someKeyName"]];

    // read some values, write some values: int someInt = [someUsefulArray objectAtIndex:3]; // etc.
    // store array values back to NSUserDefaults . . .

    // IS THERE A WAY TO READ AND WRITE DIRECTLY TO INDEX 3 of the NSUserDefaults array instead???

    [someUsefulArray release]
}
  • 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-21T02:54:26+00:00Added an answer on May 21, 2026 at 2:54 am

    I’ve actually done the same thing in a shipping application. Sure, it doesn’t feel elegant, but it does the job.

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

Sidebar

Related Questions

I have to pre-populate two calendars with values. I need it to be in
I need some help understanding this bit of code pre { white-space: pre; white-space:
I have a couple of pre-existing applications which I need to run in one
I have a strong use case for pre-allocating all the memory I need upfront
For example, I need to do some pre-processing of source files before compiling. How
I created a pre-populate SQL Lite DB an added it to my app as
So I have this SQL table that I need to update. Now we use
I've got an associative array in php that I want to stick into a
I have a JSF page where I am need to pre-check one of the
I have a global NSMutableArray and I need to update it with values. NSMutableArray

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.