Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Richard Charles via Cocoa-dev
> On Apr 3, 2021, at 9:56 AM, Gabriel Zachmann wrote: > > Sorry for asking: the shared instance is the one that is persistent, right? Looks like an instance created from alloc init would not be useful in your situation. It appears you would be in charge of persistence. NSUserDefault ,

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Sandor Szatmari via Cocoa-dev
Gabriel > On Apr 3, 2021, at 10:55, Gabriel Zachmann wrote: > >  >> >>> >>> [ [NSUserDefaults userDefaultsWithName:@"monitor-name"] boolForKey:@"some >>> key"] >> >> I thought -addSuiteNamed: would allow you to maintain/add a suite of >> defaults for each monitor. > > Maybe. > > The

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Steve Mills via Cocoa-dev
> On Apr 3, 2021, at 12:00, Gabriel Zachmann via Cocoa-dev > wrote: > > Oh, and BTW: what happens if I do this: > >NSDictionary * monitor_user_defaults = [ [NSUserDefaults standardDefaults] > dictionaryForKey: displayName_]; >[monitor_user_defaults setObject: anArray forKey:

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Gabriel Zachmann via Cocoa-dev
Oh, and BTW: what happens if I do this: NSDictionary * monitor_user_defaults = [ [NSUserDefaults standardDefaults] dictionaryForKey: displayName_]; [monitor_user_defaults setObject: anArray forKey: @"Pref1"]; Will that make NSUserDefaults automagically write the new preferences/defaults

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Steve Mills via Cocoa-dev
> On Apr 3, 2021, at 11:02, Gabriel Zachmann via Cocoa-dev > wrote: > >  >> >> Why not use your top level NSUserDefaults as a dictionary and use each >> monitor name as a key for each object in the dictionary? Is that too clunky? > > I was thinking of that, but I was hoping for a more

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Gabriel Zachmann via Cocoa-dev
> Why not use your top level NSUserDefaults as a dictionary and use each > monitor name as a key for each object in the dictionary? Is that too clunky? I was thinking of that, but I was hoping for a more elegant solution. With the dictionary-per-monitor your suggesting, I guess I would have

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Gabriel Zachmann via Cocoa-dev
>> Can you explain to me, what is the difference between >> [[NSUserDefaults alloc] init] >> and >> [NSUserDefaults standardDefaults] >> ? >> I didn't get that from Apple's docs. >> > > > [...] > So it appears that using alloc int does not return the shared instance. Sorry for asking: the

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Richard Charles via Cocoa-dev
> On Apr 3, 2021, at 8:59 AM, Gabriel Zachmann wrote: > > Thanks a lot for your response! > >> How about something like this? >> >>NSUserDefaults *monitor1 = [[NSUserDefaults alloc] init]; >>[monitor1 setBool:YES forKey:@"MyKey”]; >> >>BOOL value = [monitor1 boolForKey:@"MyKey"];

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Alex Zavatone via Cocoa-dev
Why not use your top level NSUserDefaults as a dictionary and use each monitor name as a key for each object in the dictionary? Is that too clunky? https://developer.apple.com/documentation/foundation/nsuserdefaults A default object must be a property list—that is, an instance of (or for

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Gabriel Zachmann via Cocoa-dev
Thanks a lot for your response! > How about something like this? > > NSUserDefaults *monitor1 = [[NSUserDefaults alloc] init]; > [monitor1 setBool:YES forKey:@"MyKey”]; > > BOOL value = [monitor1 boolForKey:@"MyKey"]; So, where is the kind of monitor encoded? I mean, how does the

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Gabriel Zachmann via Cocoa-dev
>> >> [ [NSUserDefaults userDefaultsWithName:@"monitor-name"] boolForKey:@"some >> key"] > > I thought -addSuiteNamed: would allow you to maintain/add a suite of defaults > for each monitor. Maybe. The doc says: """ The suiteName domain is similar to a bundle identifier string, but isn't

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Richard Charles via Cocoa-dev
> On Apr 3, 2021, at 5:40 AM, Gabriel Zachmann via Cocoa-dev > wrote: > > But what I would like to have is a mechanism that lets me manage different > user defaults when the app is running on different monitors. > Something like > > [ [NSUserDefaults userDefaultsWithName:@"monitor-name"]

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Sandor Szatmari via Cocoa-dev
Gabriel, > On Apr 3, 2021, at 07:41, Gabriel Zachmann via Cocoa-dev > wrote: > > Thanks a lot for your response! > >> User Defaults are now stored in an opaque in memory DB, and while the >> various files may still play a role, you can't make any assumptions about >> them anymore. > >

Re: Several different NSUserDefaults in the same app?

2021-04-03 Thread Gabriel Zachmann via Cocoa-dev
Thanks a lot for your response! > User Defaults are now stored in an opaque in memory DB, and while the various > files may still play a role, you can't make any assumptions about them > anymore. Yes, I understand that. > > That being said, [NSUserDefaults.standardUserDefaults