Mac Developer Library

Developer

AppKit Framework Reference NSController Class Reference

Options
Deployment Target:

On This Page
Language:

NSController

The NSController class is an abstract class that implements the NSEditor and NSEditorRegistration informal protocols required for controller classes.

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.3 and later.
  • Invoked to inform the receiver that editor has uncommitted changes that can affect the receiver.

    Declaration

    Swift

    func objectDidBeginEditing(_ editor: AnyObject!)

    Objective-C

    - (void)objectDidBeginEditing:(id)editor

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Invoked to inform the receiver that editor has committed or discarded its changes.

    Declaration

    Swift

    func objectDidEndEditing(_ editor: AnyObject!)

    Objective-C

    - (void)objectDidEndEditing:(id)editor

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Causes the receiver to attempt to commit any pending edits, returning YEStrue if successful or no edits were pending.

    Declaration

    Swift

    func commitEditing() -> Bool

    Objective-C

    - (BOOL)commitEditing

    Discussion

    The receiver invokes commitEditing on any current editors, returning their response. A commit is denied if the receiver fails to apply the changes to the model object, perhaps due to a validation error.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Attempts to commit any pending changes in known editors of the receiver.

    Declaration

    Swift

    func commitEditingWithDelegate(_ delegate: AnyObject!, didCommitSelector didCommitSelector: Selector, contextInfo contextInfo: UnsafeMutablePointer<Void>)

    Objective-C

    - (void)commitEditingWithDelegate:(id)delegate didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo

    Parameters

    delegate

    An object that can serve as the receiver's delegate. It should implement the method specified by didCommitSelector.

    didCommitSelector

    A selector that is invoked on delegate. The method specified by the selector must have the same signature as the following method:

    • - (void)editor:(id)editor didCommit:(BOOL)didCommit contextInfo:(void *)contextInfo
    contextInfo

    Contextual information that is sent as the contextInfo argument to delegate when didCommitSelector is invoked.

    Discussion

    Provides support for the NSEditor informal protocol. This method attempts to commit pending changes in known editors. Known editors are either instances of a subclass of NSController or (more rarely) user interface controls that may contain pending edits—such as text fields—that registered with the context using objectDidBeginEditing: and have not yet unregistered using a subsequent invocation of objectDidEndEditing:.

    The receiver iterates through the array of its known editors and invokes commitEditing on each. The receiver then sends the message specified by the didCommitSelector selector to the specified delegate.

    The didCommit argument is the value returned by the editor specified by editor from the commitEditing message. The contextInfo argument is the same value specified as the contextInfo parameter—you may use this value however you wish.

    If an error occurs while attempting to commit, for example if key-value coding validation fails, your implementation of this method should typically send the view in which editing is being performed a presentError:modalForWindow:delegate:didRecoverSelector:contextInfo: message, specifying the view's containing window.

    You may find this method useful in some situations (typically if you are using Cocoa Bindings) when you want to ensure that pending changes are applied before a change in user interface state. For example, you may need to ensure that changes pending in a text field are applied before a window is closed. See also commitEditing which performs a similar function but which allows you to handle any errors directly, although it provides no information beyond simple success/failure.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Discards any pending changes by registered editors.

    Declaration

    Swift

    func discardEditing()

    Objective-C

    - (void)discardEditing

    Discussion

    The receiver invokes discardEditing on any current editors.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • editing editing Property

    A Boolean value indicating if any editors are registered with the controller. (read-only)

    Declaration

    Swift

    var editing: Bool { get }

    Objective-C

    @property(getter=isEditing, readonly) BOOL editing

    Discussion

    The value of this property is YEStrue when an editor is registered with the controller object or NOfalse when no editor is registered.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.10 and later.