---
title: CAReplicatorLayer
framework: quartzcore
role: symbol
role_heading: Class
path: quartzcore/careplicatorlayer
---

# CAReplicatorLayer

A layer that creates a specified number of sublayer copies with varying geometric, temporal, and color transformations.

## Declaration

```swift
class CAReplicatorLayer
```

## Overview

Overview You can use a CAReplicatorLayer object to build complex layouts based on a single source layer that is replicated with transformation rules that can affect the position, rotation color, and time. The following shows a simple example: a red square is added to a replicator layer with an instance count of 5. The position of each replicated instance is offset along the x axis so that it appears to the right of the previous instance. The blue and green color channels are offset so that their values reach 0 at the final instance. let replicatorLayer = CAReplicatorLayer()       let redSquare = CALayer() redSquare.backgroundColor = NSColor.white.cgColor redSquare.frame = CGRect(x: 0, y: 0, width: 100, height: 100)       let instanceCount = 5       replicatorLayer.instanceCount = instanceCount replicatorLayer.instanceTransform = CATransform3DMakeTranslation(110, 0, 0)       let offsetStep = -1 / Float(instanceCount) replicatorLayer.instanceBlueOffset = offsetStep replicatorLayer.instanceGreenOffset = offsetStep      replicatorLayer.addSublayer(redSquare) The result of the code above is a row of five squares, with colors graduating from white to red.

Replicator layers can be nested. The following code adds replicatorLayer to a second replicator layer that offsets the position of each instance vertically and subtracts from the red channel. let outerReplicatorLayer = CAReplicatorLayer()

outerReplicatorLayer.addSublayer(replicatorLayer)

outerReplicatorLayer.instanceCount = instanceCount outerReplicatorLayer.instanceTransform = CATransform3DMakeTranslation(0, 110, 0) outerReplicatorLayer.instanceRedOffset = offsetStep The result of adding this code is to create a grid with the value of the red channel being reduced in the vertical direction.

note: The CAReplicatorLayer implementation of hitTest(_:) currently tests only the first instance of z replicator layer’s sublayers. This may change in the future.

## Topics

### Setting Instance Display Properties

- [instanceCount](quartzcore/careplicatorlayer/instancecount.md)
- [instanceDelay](quartzcore/careplicatorlayer/instancedelay.md)
- [instanceTransform](quartzcore/careplicatorlayer/instancetransform.md)

### Modifying Instance Layer Geometry

- [preservesDepth](quartzcore/careplicatorlayer/preservesdepth.md)

### Accessing Instance Color Values

- [instanceColor](quartzcore/careplicatorlayer/instancecolor.md)
- [instanceRedOffset](quartzcore/careplicatorlayer/instanceredoffset.md)
- [instanceGreenOffset](quartzcore/careplicatorlayer/instancegreenoffset.md)
- [instanceBlueOffset](quartzcore/careplicatorlayer/instanceblueoffset.md)
- [instanceAlphaOffset](quartzcore/careplicatorlayer/instancealphaoffset.md)

## Relationships

### Inherits From

- [CALayer](quartzcore/calayer.md)

### Conforms To

- [CAMediaTiming](quartzcore/camediatiming.md)
- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Advanced Layer Options

- [CAScrollLayer](quartzcore/cascrolllayer.md)
- [CATiledLayer](quartzcore/catiledlayer.md)
- [CATransformLayer](quartzcore/catransformlayer.md)
