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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:22:41+00:00 2026-06-17T13:22:41+00:00

I am trying to save an array using NSUserDefaults. I have gotten it to

  • 0

I am trying to save an array using NSUserDefaults. I have gotten it to work in other parts of my app and I can’t seem to figure out why it doesn’t work now. It seems that it is adding (null) to the userDefaults-array, but when I NSLog what I am trying to add ([mainDelegate.globalValdaFragor objectAtIndex:i]) I can see the value I want to input.

The problem seems to be that I can’t add anything to the “felPaFragor”-array, seeing as when I try to NSLog it I get (null) and when I tried it with another “random” array it worked.

RPAppDelegate *mainDelegate = (RPAppDelegate *)[[UIApplication sharedApplication]delegate];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSMutableArray *felPaFragor = [[NSMutableArray alloc] init];
felPaFragor = [[defaults valueForKey:@"felFragorArray"] mutableCopy];

[felPaFragor addObject:[mainDelegate.globalValdaFragor objectAtIndex:i]];

[defaults setObject:felPaFragor forKey:@"felFragorArray"];

Any help would be greatly appreciated.

Edit: I think I figured it out. It seems I was trying to make a mutableCopy of an empty array and that in turn made my “felPaFragor”-array buggy. Adding this made it work.

felPaFragor = [[NSMutableArray alloc] init];
if ([[defaults valueForKey:@"felFragorArray"] objectAtIndex:0] != NULL) {
    felPaFragor = [[defaults valueForKey:@"felFragorArray"] mutableCopy];
}
  • 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-17T13:22:42+00:00Added an answer on June 17, 2026 at 1:22 pm

    If after executing this:

    NSMutableArray *felPaFragor = [[NSMutableArray alloc] init];
    felPaFragor = [[defaults valueForKey:@"felFragorArray"] mutableCopy];
    

    your felPaFragor is nil, then it is highly likely that [defaults valueForKey:@"felFragorArray"] is returning nil.

    So, you have a problem with your key, or possibly the object associated to that key has never been stored in NSUserDefaults yet.

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

Sidebar

Related Questions

[[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@myArray]; I'm trying to figure out how to save and load
I am trying to save some block coverage using an array of integers that
I'm trying to save an array as an image using plt.imsave() . The original
I'm trying to save simple text data in my app using this code from
I'm trying to save some data into an array but unfortunately all the data
When trying to save the database using boost serialization, I encounter the segfault that
I'm trying to save a CUploadedFile object in local folder, I am using img
I am trying to save a simple template to pdf using the rendering plugin,
I am trying to save multiple image using this code. But instead its saving
I hav to save the values of NSUserDefault to the Array,and later on have

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.