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

The Archive Base Latest Questions

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

So I am saving 3 NSStrings from 3 UITextFields to a property list. This

  • 0

So I am saving 3 NSStrings from 3 UITextFields to a property list. This works fine, but everytime I save something new, the app overwrites the data that was saved before. So basically there is only 1 Dictionary used, but i want the app to create a new dictionary everytime i save something new, so that no data gets deleted. I have no Idea how i could do this, so please help me!! 🙂

Code:

NSMutableArray *array = [NSMutableArray arrayWithCapacity:3];
        NSArray *keys = [NSArray arrayWithObjects:@"1",@"2",@"3", nil]; 
        [array addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%@",lab.text],[NSString stringWithFormat:@"%@",lab1.text],[NSString stringWithFormat:@"%@",lab2.text], nil] forKeys:keys]]; 
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"];
        [array writeToFile:path atomically:YES];
  • 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-24T00:57:33+00:00Added an answer on May 24, 2026 at 12:57 am

    Ok I’ve got it:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
        NSString *documentsDirectory = [paths objectAtIndex:0];
    
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"];
    
        NSLog(@"path='%@'",path);
    
        NSFileManager *nfm = [[NSFileManager alloc] init];
        if([nfm fileExistsAtPath:path])
        {
    
            // if file exists, get its contents, add more entries and write back
    
            NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
            NSArray *keys = [NSArray arrayWithObjects:@"4",@"5",@"6",nil]; 
            [array addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%@",lab.text],[NSString stringWithFormat:@"%@",lab1.text],[NSString stringWithFormat:@"%@",lab2.text], nil] forKeys:keys]]; 
            NSLog(@"modified array=%@",array);
            BOOL ok = [array writeToFile:path atomically:YES];
            if(!ok){
                NSLog(@"Unable to write appended file");
                return;
            }
    
        } else {
    
            // if file doesn't exist, create a new one
    
            NSMutableArray *array = [[NSMutableArray alloc] init];
            NSArray *keys = [NSArray arrayWithObjects:@"1",@"2",@"3",nil]; 
            [array addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%@",lab.text],[NSString stringWithFormat:@"%@",lab1.text],[NSString stringWithFormat:@"%@",lab2.text], nil] forKeys:keys]]; 
            NSLog(@"new array=%@",array);
            BOOL ok = [array writeToFile:path atomically:YES];
            if(!ok){
                NSLog(@"Unable to write new file");
                return;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Java application is saving stuff in 'user.home' but on windows this does not
I am downloading images from server and saving them locally in my iphone,But sometimes
Saving data to Postscript in my app results in a Postscript file which I
I'm having trouble saving a new row in the DataGridView back to the database.
I am saving all the words from a file like so: sentence = fileName
I'm making an app where I need to save the text in multiple views
There have been a few threads on this topic but none have been able
im new with objective-c. I have problem with memory leaking when developing iphone app.
So I grab the username from the field, save it in an NSString variable:
I am working on a iphone/Ipod touch project involving saving and fetching data from

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.