This chapter demonstrated how to write a file to the file system of the iPhone and how to read it back. In addition, you saw how structured data can be represented using a property list and how you can programmatically work with a property list using a dictionary object. The next chapter shows you how to use databases to store more complex data.
EXERCISES
Answers to the exercises can be found in Appendix D.
WHAT YOU LEARNED IN THIS CHAPTER
TOPIC | KEY CONCEPTS |
Subdirectories in each of the applications folders | Documents, Library, and tmp |
Getting the path of the Documents folder |
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; |
Getting the path of the tmp directory |
-(NSString *) tempPath{ return NSTemporaryDirectory(); } |
Checking whether a file exists |
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { } |
Loading a property list from the Resources folder |
NSString *pListPath = [[NSBundle mainBundle] pathForResource:@“Apps” ofType:@“plist”]; |
Creating a mutable copy of an NSDictionary object |
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistFileName]; NSMutableDictionary *copyOfDict = [dict mutableCopy]; |
Using bundled resources in your application | Copy the resources into the application's folders, such as Documents or tmp. You should copy the resources in the application's delegate when the application has just fi nished launching. |
Exporting documents from your application | Use the UIDocumentInteractionController class. |
Enabling file sharing in your application | Set the UIFileSharingEnabled key to YES in the .plist file of your project. |
Importing documents into your application | Implement the application:openURL:sourceApplication:annotation: method in your application delegate. |
Defining a file type supported by your application | Set the CFBundleDocumentTypes key in the .plist file. |
13.59.108.176