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

# addSubview(_:positioned:relativeTo:)

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

```
func addSubview(_ view: NSView, positioned place: NSWindow.OrderingMode, relativeTo otherView: NSView?)
```

## Parameters

`view`

The view object to add to the view as a subview.

`place`

An `enum` constant specifying the position of the `aView` relative to `otherView`. Valid values are `NSWindowAbove` or `NSWindowBelow`.

`otherView`

The other view `aView` is to be positioned relative to. If `otherView` is `nil` (or isn’t a subview of the view), `aView` is added above or below all of its new siblings.

## 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

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

The array of views embedded in the current view.

[`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)