---
title: "insertSublayer(_:at:)"
framework: quartzcore
role: symbol
role_heading: Instance Method
path: "quartzcore/calayer/insertsublayer(_:at:)"
---

# insertSublayer(_:at:)

Inserts the specified layer into the receiver’s list of sublayers at the specified index.

## Declaration

```swift
func insertSublayer(_ layer: CALayer, at idx: UInt32)
```

## Parameters

- `layer`: The sublayer to be inserted into the current layer.
- `idx`: The index at which to insert aLayer. This value must be a valid 0-based index into the doc://com.apple.quartzcore/documentation/QuartzCore/CALayer/sublayers array.

## 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(_:below:)](quartzcore/calayer/insertsublayer(_:below:).md)
- [insertSublayer(_:above:)](quartzcore/calayer/insertsublayer(_:above:).md)
- [replaceSublayer(_:with:)](quartzcore/calayer/replacesublayer(_:with:).md)
