<!--
{
  "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/CATransaction",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CATransaction"
  },
  "title" : "CATransaction"
}
-->

# CATransaction

A mechanism for grouping multiple layer-tree operations into atomic updates to the render tree.

```
class CATransaction
```

## Overview

`CATransaction` is the Core Animation mechanism for batching multiple layer-tree operations into atomic updates to the render tree. Every modification to a layer tree must be part of a transaction. Nested transactions are supported.

Core Animation supports two types of transactions: *implicit* transactions and *explicit* transactions. Implicit transactions are created automatically when the layer tree is modified by a thread without an active transaction and are committed automatically when the thread’s runloop next iterates. Explicit transactions occur when the the application sends the [`CATransaction`](/documentation/QuartzCore/CATransaction) class a [`begin()`](/documentation/QuartzCore/CATransaction/begin()) message before modifying the layer tree, and a [`commit()`](/documentation/QuartzCore/CATransaction/commit()) message afterwards.

[`CATransaction`](/documentation/QuartzCore/CATransaction) allows you to override default animation properties that are set for animatable properties. You can customize duration, timing function, whether changes to properties trigger animations, and provide a handler that informs you when all animations from the transaction group are completed.

During a transaction you can temporarily acquire a recursive spin lock for managing property atomicity.

[`CATransaction`](/documentation/QuartzCore/CATransaction) supports nested transactions. The following code shows how you can fade out a layer (named `transitioningLayer`) over a 2 second duration while scaling it to three times its original size. The scale animation is within a nested transaction with its own duration of 1 second. After the outer transaction completes, a completion block removes `transitioningLayer` from its parent layer.

```swift
let transitioningLayer = CALayer()
     
// Outer transaction animates `opacity` to 0 over 2 seconds
CATransaction.begin()
CATransaction.setAnimationDuration(2)
CATransaction.setCompletionBlock {
    transitioningLayer.removeFromSuperlayer()
}
    
transitioningLayer.opacity = 0
     
// Inner transaction animates scale to (3, 3, 3) over 1 second
CATransaction.begin()
CATransaction.setAnimationDuration(1)
     
transitioningLayer.transform = CATransform3DMakeScale(3, 3, 3)
     
CATransaction.commit() // Commits inner transaction
CATransaction.commit() // Commits outer transaction
```

## Topics

### Creating and Committing Transactions

[`begin()`](/documentation/QuartzCore/CATransaction/begin())

Begin a new transaction for the current thread.

[`commit()`](/documentation/QuartzCore/CATransaction/commit())

Commit all changes made during the current transaction.

[`flush()`](/documentation/QuartzCore/CATransaction/flush())

Flushes any extant implicit transaction.

### Overriding Animation Duration and Timing

[`animationDuration()`](/documentation/QuartzCore/CATransaction/animationDuration())

Returns the animation duration used by all animations within this transaction group.

[`setAnimationDuration(_:)`](/documentation/QuartzCore/CATransaction/setAnimationDuration(_:))

Sets the animation duration used by all animations within this transaction group.

[`animationTimingFunction()`](/documentation/QuartzCore/CATransaction/animationTimingFunction())

Returns the timing function used for all animations within this transaction group.

[`setAnimationTimingFunction(_:)`](/documentation/QuartzCore/CATransaction/setAnimationTimingFunction(_:))

Sets the timing function used for all animations within this transaction group.

### Temporarily Disabling Property Animations

[`disableActions()`](/documentation/QuartzCore/CATransaction/disableActions())

Returns whether actions triggered as a result of property changes made within this transaction group are suppressed.

[`setDisableActions(_:)`](/documentation/QuartzCore/CATransaction/setDisableActions(_:))

Sets whether actions triggered as a result of property changes made within this transaction group are suppressed.

### Getting and Setting Completion Block Objects

[`completionBlock()`](/documentation/QuartzCore/CATransaction/completionBlock())

Returns the completion block object.

[`setCompletionBlock(_:)`](/documentation/QuartzCore/CATransaction/setCompletionBlock(_:))

Sets the completion block object.

### Managing Concurrency

[`lock()`](/documentation/QuartzCore/CATransaction/lock())

Attempts to acquire a recursive spin-lock lock, ensuring that returned layer values are valid until unlocked.

[`unlock()`](/documentation/QuartzCore/CATransaction/unlock())

Relinquishes a previously acquired transaction lock.

### Getting and Setting Transaction Properties

[`setValue(_:forKey:)`](/documentation/QuartzCore/CATransaction/setValue(_:forKey:))

Sets the arbitrary keyed-data for the specified key.

[`value(forKey:)`](/documentation/QuartzCore/CATransaction/value(forKey:))

Returns the arbitrary keyed-data specified by the given key.

### Constants

[Transaction properties](/documentation/QuartzCore/transaction-properties)

These constants define the property keys used by [`value(forKey:)`](/documentation/QuartzCore/CATransaction/value(forKey:)) and [`setValue(_:forKey:)`](/documentation/QuartzCore/CATransaction/setValue(_:forKey:)).



---

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)