How To Use Archiving In iPhone

In this example we will see Archiving using pList . This is the very easy to use. Let see how it will be worked.

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

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 usingPlistViewController class for you. Expand Resources and notice the template generated a separate nib, usingPlistViewController.xib, for the “usingPlist”.

Step 4: We need to add one more class in the Project. Select Classes -> add -> NewFile ->Cocoa Touch Class -> Objective C class -> Subclass of -> select NSObject and give the class name “fourLines”.

Step 5: We add two pList in the Resource folder and give names “newDocumentData.plist” and “data.plist”.

Step 6: In the usingPlistViewController.h file we have added UITextField and UINavigationController and two method.So make the following changes in the file.




Step 7: Double click the usingPlistViewController.xib file and open it to the Interface  Builder. Open the view window, first drag four UITextField and UILabel and place it to the view window, change the label name into Line 1: ,Line 2: ,Line 3: , Line 4:(see the figure below). Now Connect File’s Owner icon to the View icon and select view. Select File’s Owner icon to the first textfield and select text1. Follow the same procedure for next three textfield and select text2, text3 and text4 . Select the first textfield and bring up Connection Inspector, and drag Did End On Exit to the File’s Owner icon and select updateText: Action. Follow the same procedure for next three textfileds. You have done all the connection now save the usingPlistViewController.xib, close it and go back to the Xcode.

Step 8: Open the usingPlistViewController.m file and make the following changes in the file:




Step 9: In the fourLines.h file make the following changes :




Step 10: Open the fourLines.m file and make the following changes:




Step 11: Now compile and run the application in the Simulator.

You can Download SourceCode from here usingArchiveExercise

Leave a Comment: