<!--
{
  "availability" : [
    "macOS: 10.9.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSStackView/setVisibilityPriority(_:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSStackView(im)setVisibilityPriority:forView:"
  },
  "title" : "setVisibilityPriority(_:for:)"
}
-->

# setVisibilityPriority(_:for:)

Sets the Auto Layout priority for a view to remain attached to the stack view when Auto Layout reduces the stack view’s size.

```
func setVisibilityPriority(_ priority: NSStackView.VisibilityPriority, for view: NSView)
```

## Parameters

`priority`

The visibility priority for a specified view. Valid values are those in the [`NSStackView.VisibilityPriority`](/documentation/AppKit/NSStackView/VisibilityPriority) enumeration.

`view`

The view whose visibility priority you are setting.
  
  > Important:
  > If you attempt to set visibility priority for a view that is not in the stack view, the system raises an exception.

## Discussion

When Auto Layout reduces the stack view’s size (such as when a user reduces the size of the window containing the stack view), causing one or more views to no longer fit, the stack view detaches views in order of increasing *visibility priority*. A view with lower visibility priority detaches before a view with higher visibility priority. A set of views with identical, detachable visibility priority are all detached or reattached together. A view with the highest possible visibility priority never detaches.

A view in a detached state is not present in the stack view’s view hierarchy, but it still consumes memory.

The default visibility priority for a view is [`mustHold`](/documentation/AppKit/NSStackView/VisibilityPriority/mustHold), resulting in the view never detaching.

To allow a view to detach as needed by the stack view, set a visibility priority of [`detachOnlyIfNecessary`](/documentation/AppKit/NSStackView/VisibilityPriority/detachOnlyIfNecessary). To force a view to detach regardless of the enclosing view’s size, set a visibility priority of [`notVisible`](/documentation/AppKit/NSStackView/VisibilityPriority/notVisible). To explicitly reattach a view to a stack view, set a visibility priority of [`mustHold`](/documentation/AppKit/NSStackView/VisibilityPriority/mustHold).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)