---
title: "insertSubview(_:at:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiview/insertsubview(_:at:)"
---

# insertSubview(_:at:)

Inserts a subview at the specified index.

## Declaration

```swift
func insertSubview(_ view: UIView, at index: Int)
```

## Parameters

- `view`: The view to insert. This value cannot be nil.
- `index`: The index in the array of the doc://com.apple.uikit/documentation/UIKit/UIView/subviews property at which to insert the view. Subview indices start at 0 and cannot be greater than the number of subviews.

## Discussion

Discussion This method establishes a strong reference to view and sets its next responder to the receiver, which is its new superview. Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview.

## See Also

### Managing the view hierarchy

- [superview](uikit/uiview/superview.md)
- [subviews](uikit/uiview/subviews.md)
- [window](uikit/uiview/window.md)
- [addSubview(_:)](uikit/uiview/addsubview(_:).md)
- [bringSubviewToFront(_:)](uikit/uiview/bringsubviewtofront(_:).md)
- [sendSubviewToBack(_:)](uikit/uiview/sendsubviewtoback(_:).md)
- [removeFromSuperview()](uikit/uiview/removefromsuperview().md)
- [insertSubview(_:aboveSubview:)](uikit/uiview/insertsubview(_:abovesubview:).md)
- [insertSubview(_:belowSubview:)](uikit/uiview/insertsubview(_:belowsubview:).md)
- [exchangeSubview(at:withSubviewAt:)](uikit/uiview/exchangesubview(at:withsubviewat:).md)
- [isDescendant(of:)](uikit/uiview/isdescendant(of:).md)
