Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not entirely sure what you're getting at, but the general approach as far as using a file from your application's bundle is to copy it into the document directory as follows:</p> <ol> <li><p>Check (on first launch, startup or as required) for the presence of the file in your document directory.</p></li> <li><p>If it's not present, copy the "install" version of the file from your bundle into the document directory.</p></li> </ol> <p>In terms of some sample code, I've a method I use for such purposes as follows:</p> <pre><code>- (BOOL)copyFromBundle:(NSString *)fileName { BOOL copySucceeded = NO; // Get our document path. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentPath = [searchPaths objectAtIndex:0]; // Get the full path to our file. NSString *filePath = [documentPath stringByAppendingPathComponent:fileName]; NSLog(@"copyFromBundle - checking for presence of \"%@\"...", fileName); // Get a file manager NSFileManager *fileManager = [NSFileManager defaultManager]; // Does the database already exist? (If not, copy it from our bundle) if(![fileManager fileExistsAtPath:filePath]) { // Get the bundle location NSString *bundleDBPath = [[NSBundle mainBundle] pathForResource:fileName ofType:nil]; // Copy the DB to our document directory. copySucceeded = [fileManager copyItemAtPath:bundleDBPath toPath:filePath error:nil]; if(!copySucceeded) { NSLog(@"copyFromBundle - Unable to copy \"%@\" to document directory.", fileName); } else { NSLog(@"copyFromBundle - Succesfully copied \"%@\" to document directory.", fileName); } } else { NSLog(@"copyFromBundle - \"%@\" already exists in document directory - ignoring.", fileName); } return copySucceeded; } </code></pre> <p>This will check for the presence of the named file in your document directory and copy the file from your bundle if it doesn't already exist.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload