SUMMARY

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

  1. Describe the uses of the various subfolders contained within an application's folder.
  2. What is the difference between the NSDictionary and NSMutableDictionary classes?
  3. Name the paths of the Documents and tmp folders on a real device.
  4. Name the class that provides in-app support for exporting documents from your application.
  5. What key should be set in order to allow file sharing support for your application?
  6. What key is used to register a new file type with iOS to inform it that your application is capable of handling it?

Answers to the exercises can be found in Appendix D.

imageWHAT 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.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.108.176