Mac Developer Library

Developer

AppKit Framework Reference NSViewController Class Reference

Options
Deployment Target:

On This Page
Language:

NSViewController

A view controller manages a view, typically loaded from a nib file. More...

Inheritance


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.5 and later.
  • Returns an NSViewController object initialized to the nib file in the specified bundle.

    Declaration

    Swift

    init?(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?)

    Objective-C

    - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    Parameters

    nibNameOrNil

    The name of the nib file, without any leading path information.

    nibBundleOrNil

    The bundle in which to search for the nib file. If you specify nil, this method looks for the nib file in the main bundle.

    Return Value

    The initialized NSViewController object, or nil if there were errors during initialization or if the nib file could not be located.

    Discussion

    The NSViewController object looks for the nib file in the bundle's language-specific project directories first, followed by the Resources directory.

    The specified nib file should typically have the class of the file's owner set to NSViewController, or a custom subclass, with the view outlet connected to a view.

    If you pass in a nil for nibNameOrNil then nibName will return nil and loadView will throw an exception; in this case you must invoke setView: before view is invoked, or override loadView.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Instantiates a view from a nib file and sets the value of the view property.

    Declaration

    Swift

    func loadView()

    Objective-C

    - (void)loadView

    Discussion

    This method connects an instantiated view from a nib file to the view property of the view controller. This method is called by the system, and is exposed in this class so you can override it to add behavior immediately before or after nib loading.

    Do not call this method. If you require this method to be called, access the view property.

    Do not invoke this method from other objects unless you take care to avoid redundant invocations. The default implementation of the loadView method handles redundant invocations correctly, but a view controller subclass might not. To be safe, other objects should instead access a view controller’s view property.

    The loadView method first obtains the values of the view controller’s nibName and nibBundle properties. It then employs the NSNib class to instantiate the specified nib file via the instantiateWithOwner:topLevelObjects: method, providing the view controller object as the owner parameter.

    For this method to work correctly, you need to have specified the file’s owner of the nib file, in Interface Builder, to be NSViewController. You also need to have correctly connected the view outlet of the file's owner to the intended view in the nib file. Then, at runtime, the nib loading machinery sets the value of the view controller’s view property to the nib file’s instantiated view.

    Prior to OS X v10.10, the loadView method did not provide well-defined behavior if the nibName property’s value was nil. In OS X v10.10 and later, however, you get correct behavior without specifying a nib name as long as the nib file’s name is the same as that of the view controller. For example, if you have a view controller subclass called MyViewController and a nib file with the same name, you can employ the convenient initialization pattern [[MyViewController alloc] init].

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    See Also

    – viewDidLoad

  • The object whose value is presented in the receiver’s primary view.

    Declaration

    Swift

    var representedObject: AnyObject?

    Objective-C

    @property(strong) id representedObject

    Discussion

    This property retains the object you provide to it; it does not copy it. In another words, a view controller has a to-one relationship with its represented object and does not own it as an attribute.

    The representedObject property is key-value coding and key-value observing compliant. When you use the represented object as the file's owner of a nib file, you can bind controls to the file's owner using key paths that start with the string representedObject.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • nibBundle nibBundle Property

    The nib bundle to be loaded to instantiate the receiver’s primary view. (read-only)

    Declaration

    Swift

    var nibBundle: NSBundle? { get }

    Objective-C

    @property(strong, readonly) NSBundle *nibBundle

    Discussion

    This property’s value is the bundle you provide to the nibBundleOrNil parameter in the initWithNibName:bundle: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    See Also

    nibName

  • nibName nibName Property

    The name of the nib file to be loaded to instantiate the receiver’s primary view. (read-only)

    Declaration

    Swift

    var nibName: String? { get }

    Objective-C

    @property(copy, readonly) NSString *nibName

    Discussion

    This property’s value is the name you provide to the nibNameOrNil parameter in the initWithNibName:bundle: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • view view Property

    The view controller’s primary view.

    Declaration

    Swift

    var view: NSView

    Objective-C

    @property(strong) NSView *view

    Discussion

    If this property’s value is not already set when you access it, the view controller invokes the loadView method. That method, in turn, sets the view from the nib file identified by the view controller’s nibName and nibBundle properties.

    If you want to set a view controller’s view directly, set this property’s value immediately after creating the view controller.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • title title Property

    The localized title of the receiver’s primary view.

    Declaration

    Swift

    var title: String?

    Objective-C

    @property(copy) NSString *title

    Discussion

    You can employ the title property as needed for your app’s user interface, such as to enable a user to choose among multiple named views in a menu or other affordance. The NSViewController class does not use this property for its own purposes.

    The title property is key-value coding and key-value observing compliant.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Attempt to commit any currently edited results 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.

    contextInfo

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

    Discussion

    The receiver must have been registered as the editor of an object using objectDidBeginEditing:, and has not yet been unregistered by a subsequent invocation of objectDidEndEditing:. When the committing has either succeeded or failed, send the delegate the message specified by didCommitSelector.

    The didCommitSelector method must have the following method signature:.

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

    If an error occurs while attempting to commit, for example if key-value coding validation fails, an implementation of this method should typically send the receiver’s view apresentError:modalForWindow:delegate:didPresentSelector:contextInfo: message, specifying the view's containing window.

    You may find this method useful in some situations 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

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns whether the receiver was able to commit any pending edits.

    Declaration

    Swift

    func commitEditing() -> Bool

    Objective-C

    - (BOOL)commitEditing

    Return Value

    Returns YEStrue if the changes were successfully applied to the model, NOfalse otherwise.

    Discussion

    A commit is denied if the receiver fails to apply the changes to the model object, perhaps due to a validation error.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Causes the receiver to discard any changes, restoring the previous values.

    Declaration

    Swift

    func discardEditing()

    Objective-C

    - (void)discardEditing

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • The storyboard from which the view controller was loaded. (read-only)

    Declaration

    Swift

    var storyboard: NSStoryboard? { get }

    Objective-C

    @property(readonly, strong) NSStoryboard *storyboard

    Discussion

    If the view controller was not loaded from a storyboard, the value of this property is nil.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Declaration

    Swift

    @IBAction func dismissController(_ sender: AnyObject?)

    Objective-C

    - (IBAction)dismissController:(id)sender

    Parameters

    sender

    Discussion

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Called after the view controller’s view has been loaded into memory.

    Declaration

    Swift

    func viewDidLoad()

    Objective-C

    - (void)viewDidLoad

    Discussion

    You can override this method to perform tasks to immediately follow the setting of the view property.

    Typically, your override would perform one-time instantiation and initialization of the contents of the view controller’s view. If you override this method, call this method on super at some point in your implementation in case a superclass also overrides this method.

    For a view controller originating in a nib file, this method is called immediately after the view property is set. For a view controller created programmatically, this method is called immediately after the loadView method completes.

    The default implementation of this method does nothing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • A Boolean value indicating whether the view controller’s view is loaded into memory. (read-only)

    Declaration

    Swift

    var viewLoaded: Bool { get }

    Objective-C

    @property(readonly, getter=isViewLoaded) BOOL viewLoaded

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Called after the view controller’s view has been loaded into memory is about to be added to the view hierarchy in the window.

    Declaration

    Swift

    func viewWillAppear()

    Objective-C

    - (void)viewWillAppear

    Discussion

    You can override this method to perform tasks prior to a view controller’s view getting added to view hierarchy, such as setting the view’s highlight color. This method is called when:

    • The view is about to be added to the view hierarchy of the view controller

    • The view controller’s window is about to become visible, such as coming to the front or becoming unhidden

    If you override this method, call this method on super at some point in your implementation in case a superclass also overrides this method.

    The default implementation of this method does nothing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Called when the view controller’s view is fully transitioned onto the screen.

    Declaration

    Swift

    func viewDidAppear()

    Objective-C

    - (void)viewDidAppear

    Discussion

    This method is called after the completion of any drawing and animations involved in the initial appearance of the view. You can override this method to perform tasks appropriate for that time, such as work that should not interfere with the presentation animation, or starting an animation that you want to begin after the view appears.

    If you override this method, call this method on super at some point in your implementation in case a superclass also overrides this method.

    The default implementation of this method does nothing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Called when the view controller’s view is about to be removed from the view hierarchy in the window.

    Declaration

    Swift

    func viewWillDisappear()

    Objective-C

    - (void)viewWillDisappear

    Discussion

    You can override this method to perform tasks that are to precede the disappearance of the view controller’s view, such as stopping a continuous animation that you started in response to the viewDidAppear method call. This method is called when:

    • The view is about to be removed from the view hierarchy of the window

    • The view is about to be hidden or obscured, such as in the case of a view controller whose parent is a tab view controller and the user switched to another tab

    • The window is being closed

    If you override this method, call this method on super at some point in your implementation in case a superclass also overrides this method.

    The default implementation of this method does nothing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Called after the view controller’s view is removed from the view hierarchy in a window.

    Declaration

    Swift

    func viewDidDisappear()

    Objective-C

    - (void)viewDidDisappear

    Discussion

    You can override this method to perform tasks associated with removing the view controller’s view from the window’s view hierarchy, such as releasing resources not needed when the view is not visible or no longer part of the window.

    If you override this method, call this method on super at some point in your implementation in case a superclass also overrides this method.

    The default implementation of this method does nothing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • The desired size of the view controller’s view, in screen units.

    Declaration

    Swift

    var preferredContentSize: NSSize

    Objective-C

    @property NSSize preferredContentSize

    Discussion

    Set this property to express the desired size for a view controller’s view. A parent view controller can consult the value of this property when performing layout.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Called during Auto Layout constraint updating to enable the view controller to mediate the process.

    Declaration

    Swift

    func updateViewConstraints()

    Objective-C

    - (void)updateViewConstraints

    Discussion

    This method gets called, for example, when the user interacts with a view in a way that causes the layout to change. When called, the default implementation of this method in turn calls the updateConstraints method on the view controller’s view.

    You can override this method to update custom view constraints, as an alternative to subclassing the view controller’s view and overriding its updateConstraints method.

    If you override this method, you must call this method on super at some point in your implementation or call the updateConstraints method on the view controller’s view.

    This method is called only for apps that link against OS X v10.10 or later.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Called just before the layout method of the view controller's view is called.

    Declaration

    Swift

    func viewWillLayout()

    Objective-C

    - (void)viewWillLayout

    Discussion

    You can override this method to perform tasks to precede the layout of the view controller’s view, such as adjusting Auto Layout constraints. If you override this method, call this method on super at some point in your implementation in case a superclass also overrides this method.

    The default implementation of this method does nothing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Called immediately after the layout method of the view controller's view is called.

    Declaration

    Swift

    func viewDidLayout()

    Objective-C

    - (void)viewDidLayout

    Discussion

    You can override this method to perform tasks to follow the completion of layout of the view controller’s view. If you override this method, call this method on super at some point in your implementation in case a superclass also overrides this method.

    The default implementation of this method does nothing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • A convenience method for adding a child view controller at the end of the childViewControllers array.

    Declaration

    Swift

    func addChildViewController(_ childViewController: NSViewController)

    Objective-C

    - (void)addChildViewController:(NSViewController *)childViewController

    Parameters

    childViewController

    The view controller to be added to the end of the childViewControllers array.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • An array of view controllers that are hierarchical children of the view controller.

    Declaration

    Swift

    var childViewControllers: [AnyObject]

    Objective-C

    @property(copy) NSArray *childViewControllers

    Discussion

    You can add or remove child view controllers by using this property. When you do, the addChildViewController: or removeFromParentViewController method gets called accordingly.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Performs a transition between two sibling child view controllers of the view controller.

    Declaration

    Swift

    func transitionFromViewController(_ fromViewController: NSViewController, toViewController toViewController: NSViewController, options options: NSViewControllerTransitionOptions, completionHandler completion: (() -> Void)?)

    Objective-C

    - (void)transitionFromViewController:(NSViewController *)fromViewController toViewController:(NSViewController *)toViewController options:(NSViewControllerTransitionOptions)options completionHandler:(void (^)(void))completion

    Parameters

    fromViewController

    A child view controller whose view is visible in the view controller’s view hierarchy.

    toViewController

    A child view controller whose view is not in the view controller’s view hierarchy.

    options

    A bitmask of options that specify how you want to perform the transition animation. For the options, see the NSViewControllerTransitionOptions enumeration.

    completion

    A block called immediately after the transition animation completes.

    Discussion

    Use this method to transition between sibling child view controllers owned by a parent view controller (which is the receiver of this method).

    This method adds the view in the toViewController view controller to the superview of the view in the fromViewController view controller. Likewise, this method removes the fromViewController view from the parent view controller’s view hierarchy sat the appropriate time. It is important to allow this method to add and remove these views.

    To create a parent/child relationship between view controllers, use the addChildViewController: method or the insertChildViewController:atIndex: method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Inserts a specified child view controller into the childViewControllers array at a specified position.

    Declaration

    Swift

    func insertChildViewController(_ childViewController: NSViewController, atIndex index: Int)

    Objective-C

    - (void)insertChildViewController:(NSViewController *)childViewController atIndex:(NSInteger)index

    Parameters

    childViewController

    The child view controller to add to the childViewControllers array.

    index

    The index in the childViewControllers array at which to insert the child view controller. This value must not be greater than the count of elements in the array.

    Discussion

    You should instead use the addChildViewController: method unless you want to perform work on child view controllers as you add them. In that case, override this method to perform that work.

    If a child view controller has a different parent when you call this method, the child is first be removed from its existing parent by calling the child’s removeFromParentViewController method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Removes a specified child controller from the view controller.

    Declaration

    Swift

    func removeChildViewControllerAtIndex(_ index: Int)

    Objective-C

    - (void)removeChildViewControllerAtIndex:(NSInteger)index

    Parameters

    index

    The index in the childViewControllers array for the child view controller you want to remove.

    Discussion

    Override this method if you want to perform work during the removal of a child view controller. If you do override this method, in your implementation call this method on super.

    If you just want to remove a child view controller, instead use use the removeFromParentViewController method

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Removes the called view controller from its parent view controller.

    Declaration

    Swift

    func removeFromParentViewController()

    Objective-C

    - (void)removeFromParentViewController

    Discussion

    Use this method to remove a child view controller from its parent view controller, unless you want to perform work during the removal. In that case, instead override the removeChildViewControllerAtIndex: method to perform that work and call that method.

    This is a convenience method that calls the removeChildViewControllerAtIndex: method, automatically supplying the appropriate index value as an argument.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Called when there is a change in value of the preferredContentSize property of a child view controller or a presented view controller.

    Declaration

    Swift

    func preferredContentSizeDidChangeForViewController(_ viewController: NSViewController)

    Objective-C

    - (void)preferredContentSizeDidChangeForViewController:(NSViewController *)viewController

    Parameters

    viewController

    The view controller whose preferredContentSize property value changed.

    Discussion

    Override this method if you want to adjust layout when a child view controller or presented view controller changes its preferred content size.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Presents another view controller using a specified, custom animator for presentation and dismissal.

    Declaration

    Swift

    func presentViewController(_ viewController: NSViewController, animator animator: NSViewControllerPresentationAnimator)

    Objective-C

    - (void)presentViewController:(NSViewController *)viewController animator:(id<NSViewControllerPresentationAnimator>)animator

    Parameters

    viewController

    The other view controller to present from the view controller.

    animator

    The animation delegate to employ for presentation and dismissal of the other view controller. The animator that you specify is retained until the dismissViewController: method is called and the dismissal animation completes.

    Discussion

    Do not call this method unless you want to use a custom animator. To use one of the standard animators to present another view controller, instead call one of the dedicated presentation methods:

    Each of these methods calls this method in turn. User interaction is blocked during presentation and dismissal.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Dismisses a presented view controller, using the same animator that presented it.

    Declaration

    Swift

    func dismissViewController(_ viewController: NSViewController)

    Objective-C

    - (void)dismissViewController:(NSViewController *)viewController

    Parameters

    viewController

    The presented view controller that you are dismissing.

    Discussion

    In OS X, this is the universal way to dismiss a view controller, no matter how it was presented.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Presents another view controller as a popover.

    Declaration

    Swift

    func presentViewController(_ viewController: NSViewController, asPopoverRelativeToRect positioningRect: NSRect, ofView positioningView: NSView, preferredEdge preferredEdge: NSRectEdge, behavior behavior: NSPopoverBehavior)

    Objective-C

    - (void)presentViewController:(NSViewController *)viewController asPopoverRelativeToRect:(NSRect)positioningRect ofView:(NSView *)positioningView preferredEdge:(NSRectEdge)preferredEdge behavior:(NSPopoverBehavior)behavior

    Parameters

    viewController

    The other view controller to present as a popover.

    positioningRect

    The content size of the popover.

    positioningView

    The view relative to which the popover should be positioned. Must not be nil, or else the view controller raises an NSInvalidArgumentException exception.

    preferredEdge

    The edge of positioningView that the popover should prefer to be anchored to.

    behavior

    The popover’s closing behavior. See the NSPopoverBehavior enumeration.

    Discussion

    This method calls the presentViewController:animator: method on self (the presenting view controller), and passes a popover animator to that method.

    The presented view controller is the delegate and the content view controller of the popover. You can use NSPopoverDelegate Protocol methods to customize the popover.

    To dismiss the popover, call the dismissViewController: method on self (the presenting view controller).

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Presents another view controller as a modal window, also known as an alert.

    Declaration

    Swift

    func presentViewControllerAsModalWindow(_ viewController: NSViewController)

    Objective-C

    - (void)presentViewControllerAsModalWindow:(NSViewController *)viewController

    Parameters

    viewController

    The other view controller to present as a modal window.

    Discussion

    This method calls the presentViewController:animator: method on self (the presenting view controller), and passes a modal window animator to that method.

    The presented view controller is the delegate and the content view controller of its window. You can use NSWindowDelegate Protocol methods to prevent the closing of the modal window, if needed.

    To dismiss the modal window, call the dismissViewController: method on self (the presenting view controller).

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Presents another view controller as a sheet.

    Declaration

    Swift

    func presentViewControllerAsSheet(_ viewController: NSViewController)

    Objective-C

    - (void)presentViewControllerAsSheet:(NSViewController *)viewController

    Parameters

    viewController

    The other view controller to present as a sheet.

    Discussion

    This method calls the presentViewController:animator: method on self (the presenting view controller), and passes a sheet animator to that method.

    The presented view controller is the delegate and the content view controller of its sheet.

    To dismiss the sheet, call the dismissViewController: method on self (the presenting view controller).

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • The immediate ancestor view controller of the view controller. (read-only)

    Declaration

    Swift

    var parentViewController: NSViewController? { get }

    Objective-C

    @property(readonly) NSViewController *parentViewController

    Discussion

    The value of this property is nil if the view controller has no parent view controller, such as if the view controller is a window’s content view controller.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • The view controllers, if any, that are currently presented by the view controller. (read-only)

    Declaration

    Swift

    var presentedViewControllers: [AnyObject]? { get }

    Objective-C

    @property(readonly, assign) NSArray *presentedViewControllers

    Discussion

    There is a one-to-many relationship between the view controller whose presentedViewControllers property you are accessing, and the view controllers it is currently presenting.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • The view controller that presented the view controller or that presented its farthest ancestor view controller. (read-only)

    Declaration

    Swift

    unowned(unsafe) var presentingViewController: NSViewController? { get }

    Objective-C

    @property(readonly, assign) NSViewController *presentingViewController

    Discussion

    The presenting view controller is the one that is ultimately responsible for presenting the view controller whose presentingViewController property you are accessing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • For a view controller that is part of an app extension, the app extension context. (read-only)

    Declaration

    Swift

    var extensionContext: NSExtensionContext? { get }

    Objective-C

    @property(readonly, retain) NSExtensionContext *extensionContext

    Discussion

    If the view controller is not part of an app extension, the value of this property is nil.

    By checking for nil you can employ this method to determine whether the view controller is part of an app or an app extension, for the purpose of conditionalizing your view controller implementation. Refer to NSExtensionContext Class Reference for information about the extension context.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • For a view controller that is part of an app extension, the preferred screen origin.

    Declaration

    Swift

    var preferredScreenOrigin: NSPoint

    Objective-C

    @property NSPoint preferredScreenOrigin

    Discussion

    Set this property to position the lower-left corner of the app extension’s primary view in screen space. To specify the desired primary view size for an app extension’s view controller, use the preferredContentSize property.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • For a view controller that is part of an app extension, the largest allowable size for the app extension’s primary view, in screen units. (read-only)

    Declaration

    Swift

    var preferredMaximumSize: NSSize { get }

    Objective-C

    @property(readonly) NSSize preferredMaximumSize

    Discussion

    An app extension should return the maximum dimensions that are potentially useful for its root view, based on the items the service has been sent. By default, the value of this property is a large or infinite size.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • For a view controller that is part of an app extension, the smallest allowable size for the app extension’s primary view, in screen units. (read-only)

    Declaration

    Swift

    var preferredMinimumSize: NSSize { get }

    Objective-C

    @property(readonly) NSSize preferredMinimumSize

    Discussion

    An app extension should return the minimum dimensions its primary view can accommodate, based on the items the app extension has been sent. By default, the value of this property is a small but non-empty size.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • For a view controller that is part of an app extension, called when its view is about to be resized.

    Declaration

    Swift

    func viewWillTransitionToSize(_ newSize: NSSize)

    Objective-C

    - (void)viewWillTransitionToSize:(NSSize)newSize

    Parameters

    newSize

    The new size for the view controller’s view.

    Discussion

    Override this method if you want to change layout in response to the change in size, potentially in an animated way.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.

  • Animation options for view transitions in a view controller.

    Declaration

    Swift

    struct NSViewControllerTransitionOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var None: NSViewControllerTransitionOptions { get } static var Crossfade: NSViewControllerTransitionOptions { get } static var SlideUp: NSViewControllerTransitionOptions { get } static var SlideDown: NSViewControllerTransitionOptions { get } static var SlideLeft: NSViewControllerTransitionOptions { get } static var SlideRight: NSViewControllerTransitionOptions { get } static var SlideForward: NSViewControllerTransitionOptions { get } static var SlideBackward: NSViewControllerTransitionOptions { get } static var AllowUserInteraction: NSViewControllerTransitionOptions { get } }

    Objective-C

    typedef enum : NSUInteger { NSViewControllerTransitionNone = 0x0, NSViewControllerTransitionCrossfade = 0x1, NSViewControllerTransitionSlideUp = 0x10, NSViewControllerTransitionSlideDown = 0x20, NSViewControllerTransitionSlideLeft = 0x40, NSViewControllerTransitionSlideRight = 0x80, NSViewControllerTransitionSlideForward = 0x140, NSViewControllerTransitionSlideBackward = 0x180, NSViewControllerTransitionAllowUserInteraction = 0x1000 } NSViewControllerTransitionOptions;

    Constants

    • None

      NSViewControllerTransitionNone

      A transition with no animation (the default). Specifying another animation option from this enumeration overrides this option.

      Available in OS X v10.10 and later.

    • Crossfade

      NSViewControllerTransitionCrossfade

      A transition animation that fades the new view in and simultaneously fades the old view out. You can combine this animation option with any of the “slide” options in this enumeration.

      Available in OS X v10.10 and later.

    • SlideUp

      NSViewControllerTransitionSlideUp

      A transition animation that slides the old view up while the new view comes into view from the bottom. In other words, both views slide up.

      Available in OS X v10.10 and later.

    • SlideDown

      NSViewControllerTransitionSlideDown

      A transition animation that slides the old view down while the new view slides into view from the top. In other words, both views slide down.

      Available in OS X v10.10 and later.

    • SlideLeft

      NSViewControllerTransitionSlideLeft

      A transition animation that slides the old view to the left while the new view slides into view from the right. In other words, both views slide to the left.

      Available in OS X v10.10 and later.

    • SlideRight

      NSViewControllerTransitionSlideRight

      A transition animation that slides the old view to the right while the new view slides into view from the left. In other words, both views slide to the right.

      Available in OS X v10.10 and later.

    • SlideForward

      NSViewControllerTransitionSlideForward

      A transition animation that reflects the user interface layout direction (userInterfaceLayoutDirection) in a “forward” manner, as follows:

      • For left-to-right user interface layout direction, the NSViewControllerTransitionSlideLeft animation option.

      • For right-to-left user interface layout direction, the NSViewControllerTransitionSlideRight animation option.

      Available in OS X v10.10 and later.

    • SlideBackward

      NSViewControllerTransitionSlideBackward

      A transition animation that reflects the user interface layout direction (userInterfaceLayoutDirection) in a “backward” manner, as follows

      • For left-to-right user interface layout direction, the NSViewControllerTransitionSlideRight animation option.

      • For right-to-left user interface layout direction, the NSViewControllerTransitionSlideLeft animation option.

      Available in OS X v10.10 and later.

    • AllowUserInteraction

      NSViewControllerTransitionAllowUserInteraction

      A transition animation that allows user interaction during the transition.

      Available in OS X v10.10 and later.

    Discussion

    The up and down slide animation options are disjoint and you cannot combine them.

    Likewise, the left and right slide animation options are disjoint and you cannot combine them.

    User interaction with transitioning views is prevented for all animation options except the NSViewControllerTransitionAllowUserInteraction option.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.10 and later.