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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:54:51+00:00 2026-06-09T17:54:51+00:00

I am having head ache for a few hours trying to get to write

  • 0

I am having head ache for a few hours trying to get to write some info to plist file.
My plist looks like this:

<plist version="1.0">
<array>
<dict>
    <key>page</key>
    <string>page 1</string>
    <key>description</key>
    <string>description  text 1</string>
</dict>
<dict>
    <key>page</key>
    <string>page 2</string>
    <key>description</key>
    <string>description text 2</string>
</dict>
</array>
</plist>

I just want to write a new entry to plist like

page
3
description
description text 3

this is the code I use

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,   NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"bookmark.plist"]; //
NSMutableDictionary *rootArray = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
[rootArray setObject:@"Jimmy1" forKey:@"page"];
    [rootArray setObject:@"Jimmy2" forKey:@"description"];
    [rootArray writeToFile:path atomically:YES];

when I run I do not get any error message but just doest write anything to bookmark.plist, could you give me an idea on how to solve this problem?

thanks

  • 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-09T17:54:53+00:00Added an answer on June 9, 2026 at 5:54 pm

    I believe your problem is you have an array of dicts not a root dictionary. So when you init your NSMutableDictionary you’re actually getting an array.

    I think you need to init an NSMutableArray, add a new dictionary as the object that has the objects you want. then write your array to file.

    NSMutableArray *rootArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
    NSDictionary *newPage = [NSDictionary dictionaryWithObjectsAndKeys: @"Page 3", @"page", @"Description text 3", @"description"];
    
    [rootArray addObject:newPage];
    
    [rootArray writeToFile:path atomically:YES];
    

    Haven’t checked this in Xcode but I think this is the root of your problem.

    Update

    Definitely check out Rahul‘s answer. He remembered to wrap the write method in an if statement. This is definitely best practice for error handling.

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

Sidebar

Related Questions

I'm having a hardcore head-ache from trying to get complete programmatic control over rendering
I am having some trouble wrapping my head around this function: var toStr =
I'm having a bit of headache with some SQL I'm trying to write. Basically,
Having some issues getting my head around the differences between UTF-8, UTF-16, ASCII and
Having a bit of trouble wrapping my head around this one. I'm sure the
I'm having some trouble getting my head around the jquery queue method. I've got
I'm having some major headache trying to apply CSS3 transitions to a slideshow trough
I am having an absolute headache figuring this out. I badly need some help
I'm having one hell of a headache trying to figure this out for myself,
I'm having a headache trying to figure out why vim isn't copying to 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.