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

# setViews(_:in:)

Specifies an array of views for a specified gravity area in the stack view, replacing any previous views in that area.

```
func setViews(_ views: [NSView], in gravity: NSStackView.Gravity)
```

## Parameters

`views`

The array of views you are specifying for the gravity area.

`gravity`

The gravity area that you’re specifying the array of views for.  Valid values are those in the [`NSStackView.Gravity`](/documentation/AppKit/NSStackView/Gravity) enumeration, according to the stack view’s layout direction.

## Discussion

Calling this method updates the stack view’s layout, which can change the stack view size. As a result, views could detach or clip according to the clipping resistance of the stack view and the visibility priorities of its views.

A view in a detached state is not present in the stack view’s view hierarchy, but it still consumes memory. To respond to detachment and reattachment of views, implement an [`NSStackViewDelegate`](/documentation/AppKit/NSStackViewDelegate) object and assign it to the [`delegate`](/documentation/AppKit/NSStackView/delegate) property.

---

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)