How to link objects in NSDictionary in NSUserDefaults?

How to associate NSDictionary objects with multiple text fields in Interface Builder?

I would like to bind each object to a specific element in the dictionary. For example, the first text field should be bound to the Actor:

enter image description here

+5
source share
3 answers

Try adding a NSDictionaryController.xib file to you, and then bind its Controller contents to your dictionary in the user's default settings. Then you can bind the values ​​of the text field to the dictionary controller (layoutObjects).

I have never tried, but I think that it should work.

, .

-1

NSObjectController Interface Builder. " " "" "NSMutableDictionary", " ". "Content Object" "Shared User Defaults Controller", " " " " . " " .

( ..). ObjectController, "" (!) ( ).

, . Apple, , , ...

+4

: @keeluu .

, IB, "getcha", . :

// Assume 'anObjectController' is an NSObjectController.
// Assume 'userDefaultsController' is [NSUserDefaultsController sharedUserDefaultsController]
// Assume 'someDictionary' is an NSDictionary in userDefaults. 

[self.anObjectController 
    bind:NSContentBinding 
    toObject:userDefaultsController 
    withKeyPath:@"values.someDictionary"
    options:@{NSHandlesContentAsCompoundValueBindingOption: @YES}];

, , someDictionary, , , (, ), ; .

NSContentObjectBinding NSContentBinding. NSObjectController contentObject. , .

This is not an easy mistake, because the end of the Xcode code automatically jumps to NSContentBinding, and this is one of the most commonly used binding names. It just cost me a lot of trouble, so I hope I saved something for someone else.

+2
source

All Articles