---
title: "insertArrangedSubview(_:at:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uistackview/insertarrangedsubview(_:at:)"
---

# insertArrangedSubview(_:at:)

Adds the provided view to the array of arranged subviews at the specified index.

## Declaration

```swift
func insertArrangedSubview(_ view: UIView, at stackIndex: Int)
```

## Parameters

- `view`: The view to add to the array of views arranged by the stack.
- `stackIndex`: The index where the stack inserts the new view in its doc://com.apple.uikit/documentation/UIKit/UIStackView/arrangedSubviews array. This value must not be greater than the number of views currently in this array. If the index is out of bounds, this method throws an doc://com.apple.documentation/documentation/Foundation/NSExceptionName/internalInconsistencyException exception.

## Discussion

Discussion If index is already occupied, the stack view increases the size of the arrangedSubviews array and shifts all of its contents at the index and above to the next higher space in the array. Then the stack view stores the provided view at the index. The stack view also ensures that the arrangedSubviews array is always a subset of its subviews array. This method automatically adds the provided view as a subview of the stack view, if it isn’t already. When adding subviews, the stack view appends the view to the end of its subviews array. The index only affects the order of views in the arrangedSubviews array. It doesn’t affect the ordering of views in the subviews array.

## See Also

### Related Documentation

- [removeFromSuperview()](uikit/uiview/removefromsuperview().md)
- [init(arrangedSubviews:)](uikit/uistackview/init(arrangedsubviews:).md)

### Managing arranged subviews

- [addArrangedSubview(_:)](uikit/uistackview/addarrangedsubview(_:).md)
- [arrangedSubviews](uikit/uistackview/arrangedsubviews.md)
- [removeArrangedSubview(_:)](uikit/uistackview/removearrangedsubview(_:).md)
