Problems with KVO and Bindings using my own (not generic) NSUserDefaults object

I will subclass NSUserDefaults in my application. A side effect of this I cannot use [NSUserDefaults sharedUserDefaults], I must have a class method to provide my own static default value object. This was not a problem in the code, but now it has turned out to be complicated that I am connecting the settings user interface with bindings.

Generic NSUserDefaultsController uses generic defaults to exclude. Instead, I can create my own default controller in my window controller, provide it with my default static object, and attach the bindings to it. However, this does not work. When I tried using KVO on my defaults object, I did not receive any change notifications. I tried this again with the usual NSUserDefaults object (and not a subclass) and again without KVO notifications. Substituting the default shared object, KVO works exactly as I expected.

Does anyone have any ideas on how I can make bindings and KVO work when I don't use generic defaults?

+3
source share
4 answers

Since I haven't found a solution yet, I decided to take some of the advice provided to me during the last CocoaHeads Syracuse meeting and switch to using categories instead of a subclass of NSUserDefaults. Not an ideal solution, but it will allow me to overcome this problem and get back to work.

0
source

I always migrate NSUserDefaults stuff with my own custom class to make sure everything works as expected.

The workflow is essentially as follows:

  • , NSUserDefaults . , NSDictionary NSArray , .
  • , ,
  • NSUserDefaults .

, . , Apple magical NSUserDefaults, .

+2

, . init , . , , . , , , /, , .

, addSuiteNamed: NSUserDefaultsDomain. , NSUserDefaults, standardUserDefaults, .

+1

- , . NSObject (MYUserDefaults ). , (, ..). NSUserDefaults, . +sharedUserDefaults singleton. (*)

(NSWindowController AppDelegate) -sharedUserDefaults. , , (sharedUserDefaults.host). , , , , , NIB , .

(*) " " ( ). , , Apple " , , , ", ? , , . , , +allocWithZone:. +alloc . , .

+1

Source: https://habr.com/ru/post/1706817/


All Articles