Skip to Content
Beginning iOS 5 Application Development
book

Beginning iOS 5 Application Development

by Wei-Meng Lee
January 2012
Beginner content levelBeginner
655 pages
16h 35m
English
Wrox
Content preview from Beginning iOS 5 Application Development

COPYING BUNDLED RESOURCES

In the previous section, you learned how to embed a property list file into your application and then programmatically recreate the property list and save it in the Documents folder during runtime. While that example showed the various ways to manipulate a property list, in general it is much easier to simply copy the resource (such as the property list) into the Documents folder directly.

All resources embedded within your application (commonly known as bundled resources) are read-only. In order to make changes to them, you need to copy them into the application's folders, such as the Documents or tmp folders. You can do so by copying the resource when the application starts. The ideal location to perform this is in the application delegate. Using the preceding example, you could define the following copyFileInBundleToDocumentsFolder:withExtension: method in the FilesHandlingAppDelegate.m file:

#import “FilesHandlingAppDelegate.h”

#import “FilesHandlingViewController.h”

@implementation FilesHandlingAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (void) copyFileInBundleToDocumentsFolder:(NSString *) fileName
                             withExtension:(NSString *) ext {

    //--get the path of the Documents folder--
    NSArray *paths = NSSearchPathForDirectorieslnDomains(
                                      NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    //--get the path to the file you want to copy in the Documents folder--
    NSString ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering iOS 12 Programming - Third Edition

Mastering iOS 12 Programming - Third Edition

Donny Wals
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9781118144251Purchase book