• 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
Forcing NSUserDefaults being written to disk?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Forcing NSUserDefaults being written to disk?


  • Subject: Forcing NSUserDefaults being written to disk?
  • From: Pierre-Olivier Latour <email@hidden>
  • Date: Wed, 08 Jan 2003 12:51:00 -0800

Hi,

I have an application that has no UI. Its settings have to be set by editing
its defaults file (.plist). I use the following code to register the
defaults at startup:

+ (void) initialize
{
NSMutableDictionary* defaults = [NSMutableDictionary
dictionary];

[defaults setInt:640 forKey:kKey_ScreenWidth];
[defaults setInt:480 forKey:kKey_ScreenHeight];
[defaults setInt:32 forKey:kKey_ScreenDepth];
[defaults setInt:16 forKey:kKey_ZDepth];
[defaults setBool:YES forKey:kKey_VerticalSync];
[defaults setInt:0 forKey:kKey_MaxFPS];

[defaults setBool:YES forKey:kKey_LogFile];
[defaults setInt:8765 forKey:kKey_ServerPort];
[defaults setBool:NO forKey:kKey_HighPriorityThread];

[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
}

My problem is that, even if I call [[NSUserDefaults standardUserDefaults]
synchronize] when application quits (it returns true), no file is written in
~/Library/Preferences/;

According to the doc, it should be written when you call synchronize, even
if no changes have been made to the defaults...

So I tried changing artificially the defaults before calling sycnhronize
i.e:
[defaults setBool:![defaults boolForKey:kKey_VerticalSync]
forKey:kKey_VerticalSync];
[defaults setBool:![defaults boolForKey:kKey_VerticalSync]
forKey:kKey_VerticalSync];

Now a file is created but it contains only the key kKey_VerticalSync!

Any idea?

PS: I assume synchronize if buggy.

_____________________________________________________________

Pierre-Olivier Latour email@hidden
Palo Alto, USA http://www.pol-online.net
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Forcing NSUserDefaults being written to disk?
      • From: Mike Ferris <email@hidden>
    • Re: Forcing NSUserDefaults being written to disk?
      • From: Alex Rice <email@hidden>
    • Re: Forcing NSUserDefaults being written to disk?
      • From: Scott Anguish <email@hidden>
    • Re: Forcing NSUserDefaults being written to disk?
      • From: Robert Cerny <email@hidden>
  • Prev by Date: RE: Newbie Objective-C question
  • Next by Date: Conceptual problem
  • Previous by thread: Re: "Toll free bridged" types
  • Next by thread: Re: Forcing NSUserDefaults being written to disk?
  • Index(es):
    • Date
    • Thread