Re: Confusion with app settings / NSUserDefaults
Yes, although in practice I’ve seen the preferences make it to disk fairly quickly after app termination. Saagar Jha > On Aug 15, 2023, at 13:36, Gabriel Zachmann wrote: > > Ah, thanks a lot for the insights! > > Could it happen that the new settings have not been written to disk even if > the app has quit normally? > Or, in other words, there might be key/value pairs stored in cfprefsd's > internal/runtime storage, even if i have changed the app and those key/value > pairs do no loner correspond to any of the app's settings? > > Best regards, Gabriel > > > >> On 6. Aug 2023, at 12:57, Saagar Jha wrote: >> >> The plist file on disk is written to sporadically. cfprefsd is generally the >> arbiter what the real values are, and it may or may not write things to disk >> immediately. Conversely, it’s not necessarily sitting around watching the >> plist file for changes. The correct way to update user defaults in an ad-hoc >> fashion is to use the defaults command. >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Confusion with app settings / NSUserDefaults
Right, that makes sense, in particular with Saga's insights in mind. > Use the commend “defaults delete de.zach.ArtSaverApp” to delete all your > prefs. That should remove them everywhere. > smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Confusion with app settings / NSUserDefaults
Ah, thanks a lot for the insights! Could it happen that the new settings have not been written to disk even if the app has quit normally? Or, in other words, there might be key/value pairs stored in cfprefsd's internal/runtime storage, even if i have changed the app and those key/value pairs do no loner correspond to any of the app's settings? Best regards, Gabriel > On 6. Aug 2023, at 12:57, Saagar Jha wrote: > > The plist file on disk is written to sporadically. cfprefsd is generally the > arbiter what the real values are, and it may or may not write things to disk > immediately. Conversely, it’s not necessarily sitting around watching the > plist file for changes. The correct way to update user defaults in an ad-hoc > fashion is to use the defaults command. > smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Confusion with app settings / NSUserDefaults
Use the commend “defaults delete de.zach.ArtSaverApp” to delete all your prefs. That should remove them everywhere. At least that is what as worked for my in my limited experience. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Confusion with app settings / NSUserDefaults
The plist file on disk is written to sporadically. cfprefsd is generally the arbiter what the real values are, and it may or may not write things to disk immediately. Conversely, it’s not necessarily sitting around watching the plist file for changes. The correct way to update user defaults in an ad-hoc fashion is to use the defaults command. > On Aug 6, 2023, at 01:53, Gabriel Zachmann via Cocoa-dev > wrote: > > I am pretty confused with the NSUserDefaults system. > > My app stores different settings for different monitors in the > [NSUserDefaults standardUserDefaults]. > To do so, I generate > defaults_ = [NSUserDefaults standardUserDefaults]; > > Then, I create a dictionary containing the default settings and register > them, like this: > >NSDictionary * monitor_defaults = [NSDictionary > dictionaryWithObjectsAndKeys: defaultsForMonitor, displayname, nil ]; >[defaults_ registerDefaults: monitor_defaults]; >NSDictionary * monitor_user_prefs = [defaults_ dictionaryForKey: > displayname]; > > Then, I read the actual values from monitor_user_prefs. > > When the user changes a setting, I do the inverse, like this: > >.. create a new dictionary monitor_user_prefs, containing all the > key/value pairs of the settings .. >[defaults_ setObject: monitor_user_prefs forKey: displayName_]; >bool success = [defaults_ synchronize]; > > Now, the focusing part is the following. > I delete the Preferences folder in the app's container. > I can check with the the 'defaults' command line tool that it's really gone: > > % defaults read de.zach.ArtSaverApp > Domain de.zach.ArtSaverApp does not exist > > I run the app, and its settings are properly populated with the defaults I > set programmatically in the app. > E.g., DurationPerImage is 60 (sec). > > *However*, when I open the plist file in Xcode, I see four key/dictionary > pairs! > The keys are the names of some of the monitors I have used in the past, so > they are not entirely bogus. > But right now, my laptop is not connected to any external monitor, just the > internals LCD display. > So there should be really only one dictionary, with the name "Built-in Retina > Display". > > Next thing that's also very confusing is the following. > I close the app. Then I change a value in the plist using XCode. > Then I save the plist (CMD-S) in Xcode. > Then I run my app again - but the setting has not changed! > > It seems as if macOS is keeping the settings somewhere else, instead of the > plist file. > OTOH, when I change a setting in the app, the value in plist file reflects > that, even while I have the plist file open in Xcode. > > Very confused, > Gabriel. > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/saagar%40saagarjha.com > > This email sent to saa...@saagarjha.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Confusion with app settings / NSUserDefaults
I am pretty confused with the NSUserDefaults system. My app stores different settings for different monitors in the [NSUserDefaults standardUserDefaults]. To do so, I generate defaults_ = [NSUserDefaults standardUserDefaults]; Then, I create a dictionary containing the default settings and register them, like this: NSDictionary * monitor_defaults = [NSDictionary dictionaryWithObjectsAndKeys: defaultsForMonitor, displayname, nil ]; [defaults_ registerDefaults: monitor_defaults]; NSDictionary * monitor_user_prefs = [defaults_ dictionaryForKey: displayname]; Then, I read the actual values from monitor_user_prefs. When the user changes a setting, I do the inverse, like this: .. create a new dictionary monitor_user_prefs, containing all the key/value pairs of the settings .. [defaults_ setObject: monitor_user_prefs forKey: displayName_]; bool success = [defaults_ synchronize]; Now, the focusing part is the following. I delete the Preferences folder in the app's container. I can check with the the 'defaults' command line tool that it's really gone: % defaults read de.zach.ArtSaverApp Domain de.zach.ArtSaverApp does not exist I run the app, and its settings are properly populated with the defaults I set programmatically in the app. E.g., DurationPerImage is 60 (sec). *However*, when I open the plist file in Xcode, I see four key/dictionary pairs! The keys are the names of some of the monitors I have used in the past, so they are not entirely bogus. But right now, my laptop is not connected to any external monitor, just the internals LCD display. So there should be really only one dictionary, with the name "Built-in Retina Display". Next thing that's also very confusing is the following. I close the app. Then I change a value in the plist using XCode. Then I save the plist (CMD-S) in Xcode. Then I run my app again - but the setting has not changed! It seems as if macOS is keeping the settings somewhere else, instead of the plist file. OTOH, when I change a setting in the app, the value in plist file reflects that, even while I have the plist file open in Xcode. Very confused, Gabriel. smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com