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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:10:08+00:00 2026-06-09T07:10:08+00:00

When setting NSUserDefaults , I was initially using this code to set the defaults…

  • 0

When setting NSUserDefaults, I was initially using this code to set the defaults…

 NSMutableArray *array = [NSMutableArray arrayWithObjects: @"string1", @"string2", @"string3", nil];
 [[NSUserDefaults standardUserDefaults] setObject:array forKey: @"preset1"];
 [[NSUserDefaults standardUserDefaults] synchronize];

I’ve learned that I should be using this instead:

NSMutableArray *array = [NSMutableArray arrayWithObjects: @"string1", @"string2", @"string3", nil];
NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:array forKey:@"preset1"];
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];

Now I’m having an issue manipulating the objects later on in array. Here is the code I use to add/remove strings from array. It worked fine when I was initially setting the defaults manually in my first example. Now, the objects will not remove from the array. I did notice when printing the array in LLDB debugger that array is now being stored as a NSCFArray when it was just an NSArray before.

NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObjectsFromArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"preset1"]];

NSArray *stringsToRemove = @[@"string1", @"string2" ]; 

for (NSUInteger i = 0; i < stringsToRemove.count; i++) {
    [array removeObjectIdenticalTo:[stringsToRemove objectAtIndex:i]];
}

[[NSUserDefaults standardUserDefaults] setObject:array forKey: @"preset1"];
[[NSUserDefaults standardUserDefaults] synchronize];  
  • 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-09T07:10:10+00:00Added an answer on June 9, 2026 at 7:10 am

    This code works for me with your setup, after initializing the defaults the second way you described:

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    NSMutableArray *array = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"preset1"]];
    
    NSArray *stringsToRemove = [NSArray arrayWithObjects:@"string1", @"string2", nil];
    
    for (NSString *aString in stringsToRemove) {
         [array removeObjectIdenticalTo:aString];
    }
    
    [defaults setObject:array forKey: @"preset1"];
    [defaults synchronize];  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using an user defaults which contains array of dates .in this array
Setting onchange event for CheckBoxList using the following code doesn't work. chkListUserGroup.Attributes.Add(onchange, document.forms[0].isRecordModified.value='true';); How
Using NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; , I use calls like BOOL boolFromPrefs =
I'm using +[NSUserDefaults standardUserDefaults] to store application settings. This consists of roughly a dozen
I'm using NSUSerDefaults to store user preferences. I remember reading somewhere that setting the
I'm using NSUserDefaults for a Settings Application. This is a pristine copy and I
I am trying to convert string into NSDate using following code. NSString *old =
Objective: I want to set iphone Application Preferences at run time In Setting.Bundle I
I have set up a preference using multi_preference in my Root.plist in my Settings.bundle
I have this line of code being called when the user taps a row

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.