In this application we enter our data to the textfield and save those data to the property list when application quits and reload data again from property list when application launched. So let see how it will be worked.

Step 1: Create a application using View base application template. Give the application name “DataPersistence”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the DataPersistenceViewController class for you. Expand Resources and notice the template generated a separate nib, DataPersistenceViewController.xib, for the “DataPersistence”.

Step 4: We need to add one property list in the Resource folder.

Step 5: Open the DataPersistenceViewController.h file and we have added two TextField  Outlet ,defined a constant for filename  and  add two methods.So make the following changes in the file.

#import <UIKit/UIKit.h>
#define kPlistname @"Information.plist"

@interface DataPersistanceViewController : UIViewController {

        IBOutlet UITextField *field1;
        IBOutlet UITextField *field2;
@property (nonatomic,retain) UITextField *field1;
@property (nonatomic,retain) UITextField *field2;

-(NSString *)dataFilePath;
-(void)applicationWillTerminate:(NSNotification *)notification;

Step 6: Double click the DataPersistenceViewController.xib file and open it to the Interface Builder. First drag two textField from the library and place it to the View window and drag two label from the library and place it to the view window, change the  label names into Your FirstName and Your LastName(See the figure below). Connect the File’s Owner icon to the View icon select view, connect File’s Owner icon to the first TextField and select field1. Do it same for next TextField and select field2. Now save the DataPersistenceViewController.xib file, close it and go back to the Xcode.

Step 7: In the DataPersistenceViewController.m file make the following changes :

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

-(void)applicationWillTerminate:(NSNotification *)notification
        NSMutableArray *array = [[NSMutableArray alloc] init];
        [array addObject:field1.text];
        [array addObject:field2.text];
        [array writeToFile:[self dataFilePath] atomically:YES];
        [array release];

- (void)viewDidLoad {

        NSString *filePath =[self dataFilePath];
        if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
                NSArray *array = [[NSArray alloc]initWithContentsOfFile:filePath];
                field1.text = [array objectAtIndex:0];
                field2.text = [array objectAtIndex:1];
                [array release];
                UIApplication *app = [UIApplication sharedApplication];
                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) 
                                                                                                   name:UIApplicationWillTerminateNotification object:app];
     [super viewDidLoad];

Step 8: Now compile and run the application in simulator. But remember you should type something in the textfield and press the Home button, otherwise if you exit the application, then your data will not save.

You can download source code from here DataPersistance