<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CALayer/insertSublayer(_:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CALayer(im)insertSublayer:atIndex:"
  },
  "title" : "insertSublayer(_:at:)"
}
-->

# insertSublayer(_:at:)

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

```
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 [`sublayers`](/documentation/QuartzCore/CALayer/sublayers) array.

## Discussion

---

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)