Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my header file, I might add the following:</p> <pre><code>@interface myAppDelegate : NSObject &lt;UIApplicationDelegate&gt; { ... NSString *databaseName; } extern NSString * const kDefaultDatabaseName; extern NSString * const kAppDatabaseNameKey; </code></pre> <p>In my implementation file, I would add the following:</p> <pre><code>NSString * const kDefaultDatabaseName = @"myDefaultDatabaseName"; NSString * const kAppDatabaseNameKey = @"kAppDatabaseNameKey"; @implementation myAppDelegate + (void) initialize { if ([self class] == [MyAppDelegate class]) { UIApplication* myApp = [UIApplication sharedApplication]; NSString *defaultDatabaseName = kDefaultDatabaseName; NSMutableDictionary *resourceDict = [NSMutableDictionary dictionary]; [resourceDict setObject:defaultDatabaseName forKey:kAppDatabaseNameKey]; } } - (void) applicationDidFinishLaunching:(UIApplication *)application { ... databaseName = [[NSUserDefaults standardUserDefaults] stringForKey: kAppDatabaseNameKey]; } ... - (void) applicationWillTerminate:(UIApplication *)application { ... [[NSUserDefaults standardUserDefaults] setObject:databaseName forKey:kAppDatabaseNameKey] } </code></pre> <p>When your application starts, if there are no pre-existing user defaults, <code>+initialize</code> creates a fresh <code>NSUserDefaults</code> dictionary with whatever you set to be your default database in <code>kDefaultDatabaseName</code>.</p> <p>When the application finishes launching, the member <code>databaseName</code> takes on the value set in the <code>NSUserDefaults</code> dictionary. This can be the <code>kDefaultDatabaseName</code> or whatever it has been updated to after running your application.</p> <p>While you run your application, your user may change the value of <code>databaseName</code> to something else.</p> <p>Just before the application terminates, the value of <code>databaseName</code> is written to the <code>NSUserDefaults</code> dictionary. The next time the application is opened, <code>databaseName</code> will take on the new, updated value.</p> <p>You don't have to wait for the application to terminate before writing this update to the dictionary. You could, for example, do this immediately after the user changes <code>databaseName</code> to something new. But that's up to you.</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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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