<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "tvOS: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIView/exchangeSubview(at:withSubviewAt:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIView(im)exchangeSubviewAtIndex:withSubviewAtIndex:"
  },
  "title" : "exchangeSubview(at:withSubviewAt:)"
}
-->

# exchangeSubview(at:withSubviewAt:)

Exchanges the subviews at the specified indices.

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

Each index represents the position of the corresponding view in the array in the [`subviews`](/documentation/UIKit/UIView/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`](/documentation/UIKit/UIView/subviews) array.

---

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)