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

# addSubview(_:)

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

```
func addSubview(_ view: NSView)
```

## Parameters

`view`

The view to add to the view as a subview.

## Discussion

This method also sets the view as the next responder of `aView`.

The view retains `aView`. If you use [`removeFromSuperview()`](/documentation/AppKit/NSView/removeFromSuperview()) to remove `aView` from the view hierarchy, `aView` is released. If you want to keep using `aView` after removing it from the view hierarchy (if, for example, you are swapping through a number of views), you must retain it before invoking [`removeFromSuperview()`](/documentation/AppKit/NSView/removeFromSuperview()).

## See Also

[`-  viewWillMoveToSuperview:`](/documentation/AppKit/NSView/viewWillMove(toSuperview:))

Informs the view that its superview is about to change to the specified superview (which may be `nil`).

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

The array of views embedded in the current view.

[`-  viewWillMoveToWindow:`](/documentation/AppKit/NSView/viewWillMove(toWindow:))

Informs the view that it’s being added to the view hierarchy of the specified window object (which may be `nil`).

[`nextResponder`](/documentation/AppKit/NSResponder/nextResponder)

The next responder after this one, or `nil` if it has none.



---

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)