Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSObjectController

Inherits from
Implements
Package
com.apple.cocoa.application
Availability
Available in Mac OS X v10.3 and later.
Companion guides

Overview

NSObjectController is a Cocoa bindings compatible controller class. Properties of the content object of an instance of this class can be bound to user interface elements to access and modify their values.

By default the content object of an NSObjectController instance is NSMutableDictionary. This allows a single NSObjectController instance to be used to manage many different properties referenced by key value paths. The default content object class can be changed by calling setObjectClass, which subclassers must override.

Tasks

Constructors

Managing Content

Setting the Content Class

Managing Objects

Managing Entity Names

Managing Editing

Managing Fetch Predicates

Core Data Object Contexts

Obtaining Selections

Validating Menu Items

Constructors

NSObjectController

Creates and returns an empty NSObjectController.

public NSObjectController()

Availability

Creates and returns an NSObjectController with the specified content.

public NSObjectController(Object content)

Availability

Instance Methods

add

Creates a new object of the class specified by objectClass and sets it as the receiver’s content object using addObject.

public void add(Object sender)

Discussion

The sender is typically the object that invoked this method.

Availability
See Also

addObject

Sets object as the receiver’s content object.

public void addObject(Object object)

Discussion

If the receiver's content is bound to another object or controller through a relationship key, the relationship of the “master” object is changed.

Availability
See Also

automaticallyPreparesContent

Returns true if the receiver invokes prepareContent automatically when the receiver is loaded from a nib.

public boolean automaticallyPreparesContent()

Discussion

If the receiver has a mananged object context set, it automatically fetches data from the managed object context using the current fetch predicate. The default is true..

Availability
See Also

canAdd

Returns true if an object can be added to the receiver using add.

public boolean canAdd()

Discussion

Bindings can use this method to control the enabling of user interface objects.

This property is observable using key-value observing.

Availability
See Also

canRemove

Returns true if an object can be removed from the receiver using remove.

public boolean canRemove()

Discussion

Bindings can use this method to control the enabling of user interface objects.

This property is observable using key-value observing.

Availability
See Also

content

Returns the receiver’s content object.

public Object content()

Discussion

This property is observable using key-value observing.

Availability
See Also

entityName

Returns the entity name used by the receiver to create new objects.

public NSString entityName()

Availability
See Also

fetch

Causes the receiver to fetch the data objects specified by the entity name and fetch predicate.

public void fetch(Object sender)

Availability
See Also

isEditable

Returns true if the receiver allows adding and removing objects.

public boolean isEditable()

Discussion

This property is observable using key-value observing.

Availability
See Also

managedObjectContext

Returns the receiver’s managed object context.

public NSManagedObjectContext managedObjectContext()

Availability
See Also

newObject

Creates and returns a new object of the class specified by objectClass.

public Object newObject()

Discussion

This method is called when adding and inserting objects if setAutomaticallyPreparesContent is true.

The default implementation assumes the class returned by objectClass has a standard initialization method.

Availability
See Also

objectClass

Returns the class used when creating new objects.

public Class objectClass()

Discussion

The default class is NSMutableDictionary.

This property is observable using key-value observing.

Availability
See Also

prepareContent

Typically overridden by subclasses that require additional control over the creation of new objects.

public void prepareContent()

Discussion

Subclasses that implement this method are responsible for creating the new content object and setting it as the receiver’s content object. This method is only called if setAutomaticallyPreparesContent has been set to true.

Availability
See Also

remove

Removes the receiver’s content object using removeObject.

public void remove(Object sender)

Discussion

The sender is typically the object that invoked this method.

Availability
See Also

removeObject

If object is the receiver’s content object, the receiver’s content is set to null.

public void removeObject(Object object)

Discussion

If the receiver's content is bound to another object or controller through a relationship key, the relationship of the ‘master’ object is cleared.

Availability
See Also

selectedObjects

Returns an array of all objects to be affected by editing.

public NSArray selectedObjects()

Discussion

If the receiver supports a selection mechanism the array contains key value coding compliant proxies of the selected objects; otherwise proxies for all content objects are returned. If the receiver is a concrete instance of NSObjectController, returns an array containing the receiver’s content object.

You should avoid registering for key-value observing changes for key paths that pass through this method, that is selectedObjects.firstName. Using the proxy returned by the selection method is better for performance.

This property is observable using key-value observing.

Availability
See Also

selection

Returns a proxy object representing the receiver’s selection.

public Object selection()

Discussion

If a value requested from the selection proxy using key-value coding returns multiple objects, the controller has no selection, or the proxy is not key-value coding compliant for the requested key, the appropriate marker (MultipleValuesMarker, NoSelectionMarker or NotApplicableMarker) is returned. Otherwise, the value of the key is returned. This proxy is fully key-value coding compliant.

This property is observable using key-value observing.

Availability
See Also

setAutomaticallyPreparesContent

Sets whether the receiver creates and inserts new content objects automatically when loading from a nib file.

public void setAutomaticallyPreparesContent(boolean flag)

Discussion

If flag is true and the receiver is not using a managed object context, prepareContent is used to create the content object. If flag is true and a managed object context is set, the initial content is fetched from the managed object context using the current fetch predicate.

Setting flag to true is the same as checking the “Automatically Prepares Content” option in the Interface Builder controller inspector.

Availability
See Also

setContent

Set’s the receiver’s content object to content.

public void setContent(Object content)

Availability
See Also

setEditable

Sets whether the receiver allows adding and removing objects.

public void setEditable(boolean flag)

Discussion

The default is true.

Availability
See Also

setEntityName

Sets the receiver’s entity name to entityName.

public void setEntityName(NSString entityName)

Availability
See Also

setFetchPredicate

Sets the receiver’s fetch predicate to predicate.

public void setFetchPredicate(NSPredicate predicate)

Availability
See Also

setManagedObjectContext

Sets the receiver’s managed object context to managedObjectContext.

public void setManagedObjectContext(NSManagedObjectContext managedObjectContext)

Availability
See Also

setObjectClass

Sets the object class used when creating new objects.

public void setObjectClass(Class objectClass)

Discussion

NSObjectController’s default implementation assumes that instances of objectClass are initialized using a method that takes no arguments.

Availability
See Also

validateMenuItem

Validates menu item anItem, returning true if it should be enabled, false otherwise.

public boolean validateMenuItem(_NSObsoleteMenuItemProtocol anItem)

Discussion

For example, if canAdd returns false, menu items with the add action and the receiver as the target object are disabled.

Availability


Next Page > Hide TOC


© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.