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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:01:54+00:00 2026-05-18T05:01:54+00:00

I am trying to save few property into the plist when the user starts

  • 0

I am trying to save few property into the plist when the user starts the app for the first time, and then I have to retrieve those data and show it to the user, when the user restart the app, so that I don’t have to ask for the same data again.

I am guessing this should be very straight forward, but may be I am missing something.

It would be nice if some one can point me to a sample code for doing the same thing, it would be nice if the code saves and retrieves the data from dictionary to plist and from plist to dictionary.

I looked into the Apple Property List Programming guide and used the code from Reading and Writing Property list data

http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/PropertyLists/ReadWritePlistData/ReadWritePlistData.html#//apple_ref/doc/uid/10000048i-CH8-SW1

but, when i restart my app, I don’t get back the data that I have stored.

*EDIT*

I am adding some code so that some one can point out if I am making any mistake.

I created a plist file “Data.plist” in my project Resources folder.

This is how I save data in one of my view controller

    NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Data.plist"];
//NSString *error;

NSMutableDictionary *dict = [NSMutableDictionary dictionary];


[dict setObject:@"xxxxxx" forKey:@"phoneNumber"];
[dict setObject:@"password" forKey:@"password"];
[dict setObject:@"email" forKey:@"email"];

[dict writeToFile:finalPath atomically:NO];

This is how I am reading the the data on the same view controller viewDidLoad method, because I want to load the data from when next time app starts.

    NSDictionary *dictionary;

// read "Data.plist" from application bundle
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Data.plist"];
dictionary = [NSDictionary dictionaryWithContentsOfFile:finalPath];

// dump the contents of the dictionary to the console
for (id key in dictionary) {
    NSLog(@"bundle: key=%@, value=%@", key, [dictionary objectForKey:key]);
}   

Before saving to the file i can do “po dict” at gdb and can see there are data in the file

NSLog print following error

Assertion failed: (cls), function getName, file /SourceCache/objc4_Sim/objc4-427.1.1/runtime/objc-runtime-new.m, line 3939.

Because when i load data and do “po dictionary” at gdb it is empty

  • 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-18T05:01:54+00:00Added an answer on May 18, 2026 at 5:01 am

    -[NSDictionary writeToFile:atomically:] returns YES or NO depending on whether it’s successful or not. Are you checking the return value?

    If I had to take a guess, I’d say it’s because you’re writing the file into the application bundle. You should write it elsewhere in the file system; ~/Library/Application Support/<application name> is the usual location.

    Edit:

    You can check the return value with something like:

    BOOL success = [dict writeToFile:finalPath atomically:YES];
    if (!success) {
        NSLog(@"Could not write file");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to save a huge NSArray to a file and then retrieve it...
For a few days, I have been trying to get the username to save
I am trying to save a few files that all have the same name.
Im trying to create options page in which the user can input then save
I'm trying to save some data into an array but unfortunately all the data
I'm trying to save Images the user takes with the camera 1) If I
I've been trying to use AutoMapper to save some time going from my DTOs
I am trying to save an image I have processed in my program. e.g.
I'm trying to save myself just a few keystrokes for a command I type
after being sick for a few week I am trying to get back into

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.