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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:22:52+00:00 2026-05-25T03:22:52+00:00

I am having trouble writing my file into the plist after going through many

  • 0

I am having trouble writing my file into the plist after going through many tutorials, other people’s problems and attempting it for myself. I can read the plist with no problems but I cant update it. Below are my codes on how I am writing my data into the plist. Correct me if I made any mistake.

    NSString *path = [[NSBundle mainBundle] pathForResource:@"EventAddress" ofType:@"plist"]; 
    NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
    NSArray* allmyData = [myDictionary  allValues];

    // creates and array to store only the event details
    NSMutableArray *data = [[NSMutableArray alloc] initWithArray:allmyData];
    [data addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:tfAddress.text, @"Address", tvEvents.text, @"Events", nil]];
    [myDictionary setValue:data forKey:@"Whampo"];
    BOOL flag = [myDictionary writeToFile:path atomically:YES];
    if (flag){
        NSLog(@"write to plist success");
    }
    NSLog(@"%@", myDictionary);
    [myDictionary release];

The path is correct, the file exists, my values in the textView and textField are in the array, but when it comes to the writeToFile, it does not reflect on the file located at the document directory.

EDIT 01:

I found this online, very similar to Nekto’s suggestion. But I am thinking on how to implement my code with his. I think its pretty simple, but I cant seem to figure out how to.

NSArray *paths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentDirectory = [paths objectAtIndex:0];

NSString *plistDirectory = [NSString stringWithFormat:@"%@/Enterprise",documentDirectory];

NSString *mPath = [plistDirectory stringByAppendingPathComponent:@"Downloads.plist"]; 

[mDownloadsArray writeToFile:mPath atomically:YES];

iphonesdk.blogspot taken from that site.

EDIT 02:

I used Nekto’s suggestion and it worked well. But I am curious why it is returning DocumentsEventAddress.plist rather than EventAddress.plist. My assumption is because of the
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *plistPath = [rootPath stringByAppendingString:@"EventAddress.plist"];

Where rootPath is returning Document is that right?

  • 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-25T03:22:52+00:00Added an answer on May 25, 2026 at 3:22 am

    I’m writing to file in such way:

    NSString *errorDesc = nil;
    NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *plistPath = [rootPath stringByAppendingString:TEMPLATES_PATH];
    NSDictionary *dict = [NSDictionary dictionaryWithObject:templates forKey:@"templates"];
    NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dict format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
    if (plistData)
    {
        [plistData writeToFile:plistPath atomically:YES];
    }else
    {
        NSLog(@"[Error] Application Did Enter Background {saving file error}: %@", errorDesc);
        [errorDesc release];
    }
    

    Be sure to save file in app documents directory.

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

Sidebar

Related Questions

I'm having trouble creating a directory and then opening/creating/writing into a file in the
I'm having trouble reading and writing QByteArray data to a file. My goal is
I am having trouble writing C++ code that uses a header file designed for
OK, I'm having some trouble writing multiple lines to a text file. the program
I am having trouble writing a query. I have been working with UNION on
I am having trouble writing and reading back special characters like the Euro-sign (€)
I am having trouble writing query so that I can query the content of
I'm having trouble writing maintainable CSS code when font size is specified with EM
I'm new to linq and having trouble writing two simple queries. For some reason,
I'm quite new to sql and I'm having trouble writing this i have a

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.