<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCoder/cgAffineTransform(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@F@CGAffineTransformFromString"
  },
  "title" : "cgAffineTransform(for:)"
}
-->

# cgAffineTransform(for:)

Returns a Core Graphics affine transform structure corresponding to the data in a given string.

```
class func cgAffineTransform(for string: String) -> CGAffineTransform
```

## Parameters

`string`

A string whose contents are of the form “{*a*, *b*, *c*, *d*, *tx*, *ty*}”, where *a*, *b*, *c*, *d*, *tx*, and *ty* are the floating-point component values of the <doc://com.apple.documentation/documentation/CoreGraphics/cgaffinetransform> data structure. An example of a valid string is @”{1,0,0,1,2.5,3.0}”. The string is not localized, so items are always separated with a comma. For information about the position of each value in the transform array, see <doc://com.apple.documentation/documentation/CoreGraphics/cgaffinetransform>.

## Return Value

A Core Graphics affine transform structure. If the string is not well-formed, the function returns the identity transform.

## Discussion

In general, you should use this function only to convert strings that were previously created using the [`string(for:)`](/documentation/Foundation/NSCoder/string(for:)-6yx6n) function.

---

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)