---
title: "addSubview(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsview/addsubview(_:)"
---

# addSubview(_:)

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

## Declaration

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

## Parameters

- `view`: The view to add to the view as a subview.

## Discussion

Discussion This method also sets the view as the next responder of aView. The view retains aView. If you use 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().

## See Also

### Related Documentation

- [viewWillMove(toSuperview:)](appkit/nsview/viewwillmove(tosuperview:).md)
- [subviews](appkit/nsview/subviews.md)
- [viewWillMove(toWindow:)](appkit/nsview/viewwillmove(towindow:).md)
- [nextResponder](appkit/nsresponder/nextresponder.md)

### Adding and Removing Subviews

- [addSubview(_:positioned:relativeTo:)](appkit/nsview/addsubview(_:positioned:relativeto:).md)
- [removeFromSuperview()](appkit/nsview/removefromsuperview().md)
- [removeFromSuperviewWithoutNeedingDisplay()](appkit/nsview/removefromsuperviewwithoutneedingdisplay().md)
- [replaceSubview(_:with:)](appkit/nsview/replacesubview(_:with:).md)
- [sortSubviews(_:context:)](appkit/nsview/sortsubviews(_:context:).md)
