Mac Developer Library

Developer

AppKit Framework Reference NSDictionaryController Class Reference

Options
Deployment Target:

On This Page
Language:

NSDictionaryController

Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.5 and later.

NSDictionaryController is a bindings compatible class that manages display and editing of the contents of an NSDictionary object. NSDictionaryController transforms the contents of a dictionary into an array of key-value pairs that can be bound to user interface items such as the columns of an NSTableView.

The content of an NSDictionaryController instance is specified using the inherited method setContent: or by binding an NSDictionary instance to the contentDictionary binding. New key/value pairs inserted into the dictionary are created using the newObject method. The initial key name is set to the string returned by initialKey (specified using setInitialKey: or the initialKey binding). The initial value object is set to the object returned by initialValue (specified using setInitialValue: or the initialValue binding). The initial key name is copied to the newly inserted object, while the object returned by initialValue is simply retained. As new items are inserted the controller enumerates the initial key name, resulting in key names such as “key”, “key1”, “key2”, and so on. This behavior can be customized by overriding newObject.

An NSDictionaryController instance can be configured to exclude specified keys in a dictionary from being returned by arrangedObjects using the setExcludedKeys: method or by binding an array of key names to the excludedKeys binding. Similarly, you can specify an array of key names that are always included in the arranged objects, even if they are not present in the content dictionary, using the setIncludedKeys: method or the includedKeys binding.

NSDictionaryController supports providing localized key names for the keys in the dictionary, allowing a user-friendly representation of the key name to be displayed. The localized key names are specified by a dictionary (using setLocalizedKeyDictionary: or the localizedKeyDictionary binding) or by providing a strings table (using setLocalizedKeyTable:).

The arrangedObjects method returns an array of objects that implement the NSDictionaryControllerKeyValuePair informal protocol. User interface controls are bound to the arranged objects array using key paths such as: arrangedObjects.key (displays the key name), arrangedObjects.value (displays the value for the key), or arrangedObjects.localizedKey (displays the localized key name). See NSDictionaryControllerKeyValuePair Protocol Reference for more information.

  • Creates and returns a new key-value pair to represent an entry in the content dictionary.

    Declaration

    Swift

    func newObject() -> AnyObject

    Objective-C

    - (id)newObject

    Return Value

    An object that represents the key-value pair. The object must not be autoreleased, and must implement the NSDictionaryControllerKeyValuePair informal protocol

    Discussion

    This method is invoked for insertions of new key-value pairs, as well as transforming existing dictionary entries into key-value pairs for display. Objects returned by this method must implement the NSDictionaryControllerKeyValuePair informal protocol.

    Special Considerations

    Subclass implementations must ensure that the object returned by newObject is not autoreleased.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets the localized key names that are displayed by the receiver in place of the key names.

    Declaration

    Swift

    var localizedKeyDictionary: [NSObject : AnyObject]

    Objective-C

    @property(copy) NSDictionary *localizedKeyDictionary

    Parameters

    dictionary

    A dictionary containing the localized key name strings.

    Discussion

    The dictionary contains the key names as the keys, and the localized key names as the corresponding values.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the receiver’s localization dictionary.

    Declaration

    Swift

    var localizedKeyDictionary: [NSObject : AnyObject]

    Objective-C

    @property(copy) NSDictionary *localizedKeyDictionary

    Return Value

    A dictionary containing localized string values for the key names.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the strings file used to localize key names.

    Declaration

    Swift

    var localizedKeyTable: String?

    Objective-C

    @property(copy) NSString *localizedKeyTable

    Return Value

    A string that specifies the string table to use when localizing key names.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Specifies the strings file used to localize key names.

    Declaration

    Swift

    var localizedKeyTable: String?

    Objective-C

    @property(copy) NSString *localizedKeyTable

    Parameters

    stringsFile

    Specifies the string table to use when localizing key names.

    Discussion

    The string table must reside within the application’s resource . See Strings Files in Introduction to Internationalization Programming Topics.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets the key names that are represented by a key-value pair, even if they are not present in the receiver’s content dictionary.

    Declaration

    Swift

    var includedKeys: [AnyObject]

    Objective-C

    @property(copy) NSArray *includedKeys

    Parameters

    keys

    An array containing the key names.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns an array containing the key names that are represented by a key-value pair, even if they are not present in the receiver’s content dictionary.

    Declaration

    Swift

    var includedKeys: [AnyObject]

    Objective-C

    @property(copy) NSArray *includedKeys

    Return Value

    An array containing the key names.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets the key names that are never displayed in the user interface items bound to the receiver.

    Declaration

    Swift

    var excludedKeys: [AnyObject]

    Objective-C

    @property(copy) NSArray *excludedKeys

    Parameters

    keys

    An array containing the key names.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns an array containing the key names that are never displayed in the user interface items bound to the receiver.

    Declaration

    Swift

    var excludedKeys: [AnyObject]

    Objective-C

    @property(copy) NSArray *excludedKeys

    Return Value

    An array containing the key names.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets the string used as the initial key name for a newly inserted item.

    Declaration

    Swift

    var initialKey: String

    Objective-C

    @property(copy) NSString *initialKey

    Parameters

    key

    The key name. The string is copied by the receiver.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    See Also

    – initialKey

  • Returns the string used as the initial key name for a newly inserted item.

    Declaration

    Swift

    var initialKey: String

    Objective-C

    @property(copy) NSString *initialKey

    Return Value

    The key name.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets the string used as the initial value for a newly inserted item.

    Declaration

    Swift

    var initialValue: AnyObject

    Objective-C

    @property(strong) id initialValue

    Parameters

    value

    The initial value.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the string used as the initial value for a newly inserted item.

    Declaration

    Swift

    var initialValue: AnyObject

    Objective-C

    @property(strong) id initialValue

    Return Value

    The value.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • The following constants are used to specify a binding to bind:toObject:withKeyPath:options:, infoForBinding:, unbind:, and valueClassForBinding:. See the Cocoa Bindings Reference for more information.

    Declaration

    Swift

    let NSContentDictionaryBinding: String let NSIncludedKeysBinding: String let NSExcludedKeysBinding: String let NSLocalizedKeyDictionaryBinding: String let NSInitialKeyBinding: String let NSInitialValueBinding: String

    Objective-C

    NSString *NSContentDictionaryBinding; NSString *NSIncludedKeysBinding; NSString *NSExcludedKeysBinding; NSString *NSLocalizedKeyDictionaryBinding; NSString *NSInitialKeyBinding; NSString *NSInitialValueBinding;

    Constants

    • NSContentDictionaryBinding

      NSContentDictionaryBinding

      A dictionary used as the content dictionary.

      Available in OS X v10.5 and later.

    • NSIncludedKeysBinding

      NSIncludedKeysBinding

      An array containing the key-value pairs always represented by the receiver.

      Available in OS X v10.5 and later.

    • NSExcludedKeysBinding

      NSExcludedKeysBinding

      An array containing the key names that are never displayed in the user interface items bound to the receiver.

      Available in OS X v10.5 and later.

    • NSLocalizedKeyDictionaryBinding

      NSLocalizedKeyDictionaryBinding

      A dictionary containing the localized key names that are displayed by the receiver in place of the key names.

      Available in OS X v10.5 and later.

    • NSInitialKeyBinding

      NSInitialKeyBinding

      A string used as the initial key name for newly inserted items.

      Available in OS X v10.5 and later.

    • NSInitialValueBinding

      NSInitialValueBinding

      A string used as the initial value for newly inserted items.

      Available in OS X v10.5 and later.