Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.3 and later. |
Declared in | NSObjectController.h |
Companion guides | |
Related sample code |
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 of an NSObjectController
instance is an NSMutableDictionary
object. 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.
– setContent:
– content
– setAutomaticallyPreparesContent:
– automaticallyPreparesContent
– prepareContent
– entityName
– setEntityName:
– fetch:
– setUsesLazyFetching:
– usesLazyFetching
– defaultFetchRequest
– fetchPredicate
– setFetchPredicate:
– managedObjectContext
– setManagedObjectContext:
– fetchWithRequest:merge:error:
Creates a new object and sets it as the receiver’s content object.
- (void)add:(id)sender
Typically the object that invoked this method.
Creates a new object of the appropriate entity (specified by entityName) or class (specified by objectClass
)—see newObject—and sets it as the receiver’s content object using addObject:
.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSObjectController.h
Sets the receiver’s content object.
- (void)addObject:(id)object
The content object for the receiver.
If the receiver's content is bound to another object or controller through a relationship key, the relationship of the “master” object is changed.
NSObjectController.h
Returns a Boolean value that indicates whether the receiver automatically prepares its content when it is loaded from a nib.
- (BOOL)automaticallyPreparesContent
YES
if the receiver automatically prepares its content when loaded from a nib, otherwise NO
.
See setAutomaticallyPreparesContent:
for a full explanation of "automatically prepares content."
The default is NO
.
NSObjectController.h
Returns a Boolean value that indicates whether an object can be added to the receiver using add:
.
- (BOOL)canAdd
YES
if an object can be added to the receiver using add:
, otherwise NO
.
Bindings can use this method to control the enabling of user interface objects.
This property is observable using key-value observing.
NSObjectController.h
Returns a Boolean value that indicates whether an object can be removed from the receiver.
- (BOOL)canRemove
YES
if an object can be removed from the receiver using remove:
, otherwise NO
.
Bindings can use this method to control the enabling of user interface objects.
This property is observable using key-value observing.
NSObjectController.h
Returns the receiver’s content object.
- (id)content
The receiver’s content object.
This property is observable using key-value observing.
NSObjectController.h
Returns the default fetch request used by the receiver.
- (NSFetchRequest *)defaultFetchRequest
The default NSFetchResult used by the receiver.
NSObjectController.h
Returns the entity name used by the receiver to create new objects.
- (NSString *)entityName
The entity name used by the receiver to create new objects.
NSObjectController.h
Causes the receiver to fetch the data objects specified by the entity name and fetch predicate.
- (void)fetch:(id)sender
Typically the object that invoked this method.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSObjectController.h
Returns the receiver’s fetch predicate.
- (NSPredicate *)fetchPredicate
The receiver’s fetch predicate.
NSObjectController.h
Subclasses should override this method to customize a fetch request, for example to specify fetch limits.
- (BOOL)fetchWithRequest:(NSFetchRequest *)fetchRequest merge:(BOOL)merge error:(NSError **)error
The fetch request to use for the fetch. Pass nil
to use the default fetch request.
If YES
, the receiver merges the existing content with the fetch result, otherwise the receiver replaces the entire content with the fetch result.
If an error occurs, upon return contains an NSError
object that describes the problem.
YES
if the fetch completed successfully, otherwise NO
.
This method performs a number of actions that you cannot reproduce. To customize this method, you should therefore create your own fetch request and then invoke super
’s implementation with the new fetch request.
NSObjectController.h
Initializes and returns an NSObjectController
object with the given content.
- (id)initWithContent:(id)content
The content for the receiver.
The initialized object controller, with its content object set to content.
NSObjectController.h
Returns a Boolean value that indicates whether the receiver allows adding and removing objects.
- (BOOL)isEditable
YES
if the receiver allows adding and removing objects, otherwise NO
.
This property is observable using key-value observing.
NSObjectController.h
Returns the receiver’s managed object context.
- (NSManagedObjectContext *)managedObjectContext
The receiver’s managed object context.
NSObjectController.h
Creates and returns a new object of the appropriate class.
- (id)newObject
A new object of the appropriate class. The returned object is implicitly retained, the sender is responsible for releasing it (with either release or autorelease).
If an entity name is set (see setEntityName:), the object created is an instance of the class specified for that entity (and the object is inserted into the receiver's managed object context). Otherwise the object created is an instance of the class returned by objectClass.
This method is called when adding and inserting objects if automaticallyPreparesContent
is YES
.
The default implementation assumes the class returned by objectClass
has a standard init
method without arguments. If the object class being controlled is NSManagedObject
(or a subclass thereof) its designated initializer (initWithEntity:insertIntoManagedObjectContext:
) is called instead, using the entity and managed object context specified for the receiver.
NSObjectController.h
Returns the class used when creating new non-Core Data objects.
- (Class)objectClass
The object class used when creating new non-Core Data objects (that is, if no entity has been set)—see newObject.
If an entity has been set, then the class returned by this method does not automatically reflect the class for the entity.
The default class is NSMutableDictionary
.
This property is observable using key-value observing.
NSObjectController.h
Typically overridden by subclasses that require additional control over the creation of new objects.
- (void)prepareContent
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 automaticallyPreparesContent
has been set to YES
.
NSObjectController.h
Removes the receiver’s content object.
- (void)remove:(id)sender
Typically the object that invoked this method.
Removes the receiver’s content object using removeObject:
.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSObjectController.h
Removes a given object from the receiver’s content.
- (void)removeObject:(id)object
The object to remove from the receiver.
If object is the receiver’s content object, the receiver’s content is set to nil
. If the receiver's content is bound to another object or controller through a relationship key, the relationship of the ‘master’ object is cleared.
NSObjectController.h
Returns an array of all objects to be affected by editing.
- (NSArray *)selectedObjects
An array of all objects to be affected by editing. 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, (for example, selectedObjects.firstName
). Using the proxy returned by the selection
method is better for performance.
This property is observable using key-value observing.
NSObjectController.h
Returns a proxy object representing the receiver’s selection.
- (id)selection
A proxy object representing the receiver’s selection. This object is fully key-value coding compliant, but note that it is a proxy and so does not provide the full range of functionality that might be available in the source object.
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 (NSMultipleValuesMarker
, NSNoSelectionMarker
or NSNotApplicableMarker
) is returned. Otherwise, the value of the key is returned.
This property is observable using key-value observing.
NSObjectController.h
Sets whether the receiver automatically creates and inserts new content objects automatically when loading from a nib file.
- (void)setAutomaticallyPreparesContent:(BOOL)flag
A flag that specifies whether the receiver automatically prepares its content.
If flag is YES
and the receiver is not using a managed object context, prepareContent
is used to create the content object. If flag is YES
and a managed object context is set, the initial content is fetched from the managed object context using the current fetch predicate. The default is NO
.
Setting flag to YES
is the same as checking the “Automatically Prepares Content” option in the Interface Builder controller inspector.
NSObjectController.h
Sets the receiver’s content object.
- (void)setContent:(id)content
The content object for the receiver.
NSObjectController.h
Sets whether the receiver allows adding and removing objects.
- (void)setEditable:(BOOL)flag
YES
if the the receiver should allow adding and removing objects, otherwise NO
.
The default is YES
.
NSObjectController.h
Sets the entity name used by the receiver to create new objects.
- (void)setEntityName:(NSString *)entityName
The entity name used by the receiver to create new objects.
NSObjectController.h
Sets the receiver’s fetch predicate.
- (void)setFetchPredicate:(NSPredicate *)predicate
The fetch predicate for the receiver.
The receiver uses predicate when fetching its content, for example in fetch:. If you need to customize the fetching behavior further, you can override fetchWithRequest:merge:error:.
NSObjectController.h
Sets the receiver’s managed object context.
- (void)setManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
The managed object context for the receiver.
NSObjectController.h
Sets the object class to use when creating new objects.
- (void)setObjectClass:(Class)objectClass
The object class to use when creating new objects.
NSObjectController's default implementation assumes that instances of objectClass are initialized using a standard init
method that takes no arguments.
If an entity name has been set (see setEntityName:), this method has no effect.
NSObjectController.h
Sets whether the receiver uses lazy fetching.
- (void)setUsesLazyFetching:(BOOL)enabled
Boolean value that indicates whether the receiver uses lazy fetching.
When enabled the controller uses a number of techniques that typically make managing large data sets more efficient. As with all optimizations, you should use suitable performance analysis tools (such as Instruments) to determine the best solution.
Note: Setting setUsesLazyFetching:
to YES
will cause an exception if the receiving controller is not bound to a managed object context.
NSObjectController.h
Returns a Boolean indicating whether the receiver uses lazy fetching.
- (BOOL)usesLazyFetching
YES
if the receiver uses lazy fetching, otherwise NO
.
NSObjectController.h
Returns whether the receiver can handle the action method for a user interface item.
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)item
YES
if the receiver can handle the action method; NO
if it cannot.
NSObjectController.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-12-11)