<!--
{
  "availability" : [
    "macOS: 10.10.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/AffineTransform/invert()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation15AffineTransformV6invertyyF"
  },
  "title" : "invert()"
}
-->

# invert()

Inverts the transformation matrix, if possible.

```
mutating func invert()
```

## Discussion

Matrices with a determinant less than the smallest valid representation of a double value and greater than zero are invalid for representing as an inverse. If this can potentially happen to the input transform, use the [`inverted()`](/documentation/Foundation/AffineTransform/inverted()) method instead. The [`inverted()`](/documentation/Foundation/AffineTransform/inverted()) method returns `nil` if the function can’t reliably invert the matrix.

You can calculate the determinant using the following formula:

```swift
D = (m11 * m22) - (m12 * m21)
```

---

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)