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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:10:33+00:00 2026-06-04T06:10:33+00:00

I am creating a names generator app for iPhone and this is what I

  • 0

I am creating a names generator app for iPhone and this is what I am trying to do.

  • Allow the user to save the current generated name by clicking a save button.

In order to do this, here is what is happening:

  • The current babyname is displayed in a UILabel.
  • The user presses ‘save’ and then the label.text value is appended to a NSMutableArray (I don’t think this is working in my code correctly).
  • The NSMutableArray is then saved in NSUserDefaults.
  • The contents will then be loaded in another view to populate UITableView cells.

My specific question is, am I handling this saving/persistent storage process correctly? Here is the snippet in question:

- (IBAction)saveName:(id)sender {
// save current baby name to array
NSMutableArray *babyNameArray = [[NSMutableArray alloc] init];

[babyNameArray addObject:babyname.text];

// save list of babynames to nsuserdefaults

[[NSUserDefaults standardUserDefaults] setObject:babyNameArray forKey:@"My Key"];


// for testing log names listed in nsuserdefaults
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);

}

Here is a link to the pastebin of the whole file contents (with comments): http://pastebin.com/hQRM9Azh

  • 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-04T06:10:34+00:00Added an answer on June 4, 2026 at 6:10 am

    Every time you add, you’re starting again with an empty array ([[NSMutableArray alloc] init]) – instead of starting with the existing items.

    Here’s some code which adds to the existing entries instead:

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSMutableArray *babyNameArray = [[defaults stringArrayForKey:@"My Key"] mutableCopy];
    if (!babyNameArray) babyNameArray = [[NSMutableArray alloc] init];
    [babyNameArray addObject:babyname.text];
    [defaults setObject:babyNameArray forKey:@"My Key"];
    [defaults synchronize];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody recognize this error? org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory': Post-processing of
When creating database tables I'm often stumped when trying to name my time/date/timestamp fields.
In my Java Spring web app I am creating an image file. This file
I am creating a web app where if a user clicks on Link called
I am creating a databse containing the names and coordinates of all bus stops
I read in MSDN InamingContainer is a marker interface for creating unique name. When
Exact duplicate of Function name for creating something if it's not there yet I
I am creating a MKMapView in a method named generateMap. From inside viewDidLoad, this
I'm creating a basic forum where every message contains the authors name, some text
The mailing list form I am creating has the following fields: first name, last

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.