---
title: "exchangeSubview(at:withSubviewAt:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiview/exchangesubview(at:withsubviewat:)"
---

# exchangeSubview(at:withSubviewAt:)

Exchanges the subviews at the specified indices.

## Declaration

```swift
func exchangeSubview(at index1: Int, withSubviewAt index2: Int)
```

## Parameters

- `index1`: The index of the first subview in the receiver.
- `index2`: The index of the second subview in the receiver.

## Discussion

Discussion Each index represents the position of the corresponding view in the array in the subviews property. Subview indices start at 0 and cannot be greater than the number of subviews. This method does not change the superview of either view but simply swaps their positions in the subviews array.

## 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(_:at:)](uikit/uiview/insertsubview(_:at:).md)
- [insertSubview(_:aboveSubview:)](uikit/uiview/insertsubview(_:abovesubview:).md)
- [insertSubview(_:belowSubview:)](uikit/uiview/insertsubview(_:belowsubview:).md)
- [isDescendant(of:)](uikit/uiview/isdescendant(of:).md)
