• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Saving user defaults before program ends
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Saving user defaults before program ends


  • Subject: Saving user defaults before program ends
  • From: Denver Timothy <email@hidden>
  • Date: Tue, 16 Jan 2007 17:03:41 -0700

Hi All,

I have created a preferences window and successfully made my AppController class the delegate for the window and which implements the windowWillClose method. The windowWillClose method calls [self saveUserDefaults]. In saveUserDefaults, I have two NSLog calls, one at the top and one at the bottom, and then all the [defaults setObject:forKey] calls in between. Both NSLog() are executed as expected.

The problem is that if the program is terminated (eg. Apple-Q), _none_ of the defaults are saved, but the two NSLog() calls _are_ executed as expected. However, if the the window is simply closed, the defaults are saved as expected.

Here is the relevant code:

- (void)windowWillClose:(NSNotification *)aNotification
{
	[self saveUserDefaults];
}

- (void)saveUserDefaults
{
NSLog( @"Saving user defaults" );

NSUserDefaults *defaults;
NSData *deviceAsData;

defaults = [NSUserDefaults standardUserDefaults];

// Enabled
BOOL monitoring = ( [enabledButton state] == NSOnState ? TRUE : FALSE );
[defaults setBool:monitoring forKey:@"enabled"];

...

// Device
if( device ) {
deviceAsData = [NSKeyedArchiver archivedDataWithRootObject:device];
[defaults setObject:deviceAsData forKey:@"device"];
}

[self stopMonitoring];
[self startMonitoring];

NSLog( @"Done saving defaults" );
}


Am I doing this properly? Should I be doing something different entirely?

Thanks,

Denver Timothy

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Saving user defaults before program ends
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: Core Data and "interactive" NSPopUpButtons
  • Next by Date: Re: Saving user defaults before program ends
  • Previous by thread: [Moderator] EOT Re: Add customized fields to addressbook
  • Next by thread: Re: Saving user defaults before program ends
  • Index(es):
    • Date
    • Thread