• 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
Re: NSUserDefaults synchronization in Foundation tools
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUserDefaults synchronization in Foundation tools


  • Subject: Re: NSUserDefaults synchronization in Foundation tools
  • From: Sidney San Martín <email@hidden>
  • Date: Wed, 16 Sep 2009 18:36:11 -0400

Fair enough, I s'pose that makes sense for most apps.

Since I'm targeting 10.4+, and, actually, am using CFPreferences
instead of NSUserDefaults, I wrote a simple "autosynchronize"
mechanism that synchronizes preferences if needed at the end of the
runloop. It lets multiple defaults be changed at once without extra
disk use and ensures that recently-changed ones aren't lost.

It's working just fine for this situation.

On Tue, Sep 8, 2009 at 8:56 PM, Ken Ferry <email@hidden> wrote:
> Hi Jens,
> On Tue, Sep 8, 2009 at 4:24 PM, Jens Alfke <email@hidden> wrote:
>>
>> On Sep 8, 2009, at 4:13 PM, Sidney San Martín wrote:
>>
>>> "Because this method is automatically invoked at periodic intervals, use
>>> this method only if you cannot wait for the automatic synchronization (for
>>> example, if your application is about to exit)"
>>
>> To my knowledge that's always been incorrect — the only time
>> NSUserDefaults synchronizes automatically is upon quit. The app can change a
>> default, stay running for days, then crash; and the default won't have been
>> written to disk so the change is lost. So I've always ended up calling
>> -synchronize myself, either immediately or using a perform-after-delay.
>
> No, it does actually behave as documented.  In 10.6 I know it syncs after 15
> seconds.
> I cannot find the bug where it was added, but it's been true since at least
> 10.5.
>>
>> Will NSUserDefaults ever synchronize itself itself in an app without an
>> NSApplication? If so, when and how? If not, the docs need to be ammended.
>
> Yes, it's NSTimer based.  Your app must be running the run loop for the
> synchronization to occur.
> -Ken
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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

References: 
 >NSUserDefaults synchronization in Foundation tools (From: Sidney San Martín <email@hidden>)
 >Re: NSUserDefaults synchronization in Foundation tools (From: Jens Alfke <email@hidden>)
 >Re: NSUserDefaults synchronization in Foundation tools (From: Ken Ferry <email@hidden>)

  • Prev by Date: Re: How to create subentity object inheriting from superentity object in core data
  • Next by Date: Re: How to create subentity object inheriting from superentity object in core data
  • Previous by thread: Re: NSUserDefaults synchronization in Foundation tools
  • Next by thread: NSDockTilePlugIn
  • Index(es):
    • Date
    • Thread