---
title: "replaceSublayer(_:with:)"
framework: quartzcore
role: symbol
role_heading: Instance Method
path: "quartzcore/calayer/replacesublayer(_:with:)"
---

# replaceSublayer(_:with:)

Replaces the specified sublayer with a different layer object.

## Declaration

```swift
func replaceSublayer(_ oldLayer: CALayer, with newLayer: CALayer)
```

## Parameters

- `oldLayer`: The layer to be replaced.
- `newLayer`: The layer with which to replace oldLayer.

## Discussion

Discussion If oldLayer is not in the receiver’s sublayers array, the behavior of this method is undefined.

## See Also

### Managing the layer hierarchy

- [sublayers](quartzcore/calayer/sublayers.md)
- [superlayer](quartzcore/calayer/superlayer.md)
- [addSublayer(_:)](quartzcore/calayer/addsublayer(_:).md)
- [removeFromSuperlayer()](quartzcore/calayer/removefromsuperlayer().md)
- [insertSublayer(_:at:)](quartzcore/calayer/insertsublayer(_:at:).md)
- [insertSublayer(_:below:)](quartzcore/calayer/insertsublayer(_:below:).md)
- [insertSublayer(_:above:)](quartzcore/calayer/insertsublayer(_:above:).md)
