<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSView/subviews",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSView(py)subviews"
  },
  "title" : "subviews"
}
-->

# subviews

The array of views embedded in the current view.

```
var subviews: [NSView] { get set }
```

## Discussion

This array contains zero or more `NSView` objects that represent the views embedded in the current view’s content. The current view acts as the superview for each subview. The order of the subviews may be considered as being back-to-front, but this does not imply invalidation and drawing behavior.

When loading a view from a nib or storyboard file, the order of subviews is determined by the nib or storyboard file itself and usually corresponds to the order in which the views were added. Similarly, when adding subviews programmatically, the order is based on the order in which you added them.

When performing hit-test operations on a view, you should start at the last view in this array and work backwards.

Set this property to reorder the view’s existing subviews, add or remove subviews en masse, replace all of the view’s subviews with a new set of subviews, or remove all the view’s subviews. When you assign a valid, new array of subviews, the system performs required sorting and sends [`addSubview(_:)`](/documentation/AppKit/NSView/addSubview(_:)) and [`removeFromSuperview()`](/documentation/AppKit/NSView/removeFromSuperview()) messages as necessary to leave the property with the requested new array.  Any member of the new array that isn’t already a subview of the view is added.  Any member of the view’s existing `subviews` array that isn’t in the new array is removed.  Any views that are in both [`subviews`](/documentation/AppKit/NSView/subviews) and the new array are moved in the subviews array as needed, without being removed and re-added.

This property marks the affected view and window areas as needing display.

> Note:
> The contents of this array may change at any time. If you intend to manipulate the contents of the array, work off a copy of the array.

## See Also

[`addSubview(_:positioned:relativeTo:)`](/documentation/AppKit/NSView/addSubview(_:positioned:relativeTo:))

Inserts a view among the view’s subviews so it’s displayed immediately above or below another view.

[`addSubview(_:)`](/documentation/AppKit/NSView/addSubview(_:))

Adds a view to the view’s subviews so it’s displayed above its siblings.

[`removeFromSuperview()`](/documentation/AppKit/NSView/removeFromSuperview())

Unlinks the view from its superview and its window, removes it from the responder chain, and invalidates its cursor rectangles.



---

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)