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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:30:44+00:00 2026-05-18T04:30:44+00:00

I am trying to implement a simple plist example from Beginning iPhone 3 Development

  • 0

I am trying to implement a simple plist example from “Beginning iPhone 3 Development book”. I looked into the code but my data was never saved to a plist file. Actually my project site map is as follows: Whenever you launch the app it fires in TestViewController. On the TestViewController, there is a button. When you click on the button it pushes another view controller which is PersistenceViewController and here is the code I wrote in PersistenceViewController. My doubt: is the applicationWillTerminate being called in this method? I don’t think so..please help. I am learning how to persist the data now.

In .h file #define kFilename @"data2.plist"

 - (NSString *)dataFilePath {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *path = [documentsDirectory stringByAppendingPathComponent:kFilename];
        return path;
    }

    - (void)applicationWillTerminate:(NSNotification *)notification {
        NSMutableArray *contactFormArray = [[NSMutableArray alloc] init];
        NSLog(@"App Terminate:%d",[contactFormArray count]);
        [contactFormArray addObject:nameField.text];
        [contactFormArray addObject:emailField.text];
        [contactFormArray addObject:phoneField.text];
        [contactFormArray addObject:companyField.text];
        [contactFormArray writeToFile:[self dataFilePath] atomically:YES];
        [contactFormArray release];
    }


    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {

        NSString *filePath = [self dataFilePath];
        if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
            NSArray *contactFormArray = [[NSArray alloc] initWithContentsOfFile:filePath];
            NSLog(@"Did Load:%d",[contactFormArray count]);
            nameField.text = [contactFormArray objectAtIndex:0];
            emailField.text = [contactFormArray objectAtIndex:1];
            phoneField.text = [contactFormArray objectAtIndex:2];
            companyField.text = [contactFormArray objectAtIndex:3];
            [contactFormArray release];
        }

        UIApplication *app = [UIApplication sharedApplication];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:)name:UIApplicationWillTerminateNotification object:app];
        [super viewDidLoad];

    }

Thanks for any valuable suggestions…

  • 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-18T04:30:45+00:00Added an answer on May 18, 2026 at 4:30 am

    applicationWillTerminate is called when the user quits the application (usually by pressing the Home button). Any code in this delegate method will be executed (if it doesn’t take too much time). In your case, the Plist file will be saved.

    If you are using iOS 4, pressing the Home button may send your application into the background (not quitting). If the application is killed using the debugger or crashes, that method will not be called.

    Additional Information:

    On iOS 4, multitasking is enabled in Xcode projects by default. This prevents the applicationWillTerminate method from being called. If you do not want to support multitasking, place UIApplicationExitsOnSuspend in your MyAppName-Info.plist file and check the checkbox. If you do want to support it, place any code in the applicationDidEnterBackground delegate method that you want to execute before the application enters an inactive state.

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

Sidebar

Related Questions

Iam trying to implement a simple JMS(traditional not using springs) code in eclipse using
I am trying to implement a simple login servlet but it's not working properly.
I'm trying to implement a simple priority queue from array of queues. I'm trying
I'm trying to implement a simple login system in Rails, but when I try
I'm trying to implement the simple-linkedinphp library (it's found at http://code.google.com/p/simple-linkedinphp/ ) It runs
I am trying to implement a simple example in axis2. I created the Service
I'm trying to implement a simple example of where ASP.NET changes culture. I'm running
Hey folks - I'm writing a pretty simple iPhone application. The data comes from
I'm trying to implement simple Comet chat example and for this I implemented Long
I'm trying to implement this simple example of how to synchronize threads using pthread

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.