<!--
{
  "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/cgVector(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@F@CGVectorFromString"
  },
  "title" : "cgVector(for:)"
}
-->

# cgVector(for:)

Returns a Core Graphics vector corresponding to the data in a given string.

```
class func cgVector(for string: String) -> CGVector
```

## Parameters

`string`

A string whose contents are of the form “{*dx*, *dy*}”, where *dx* is the x-coordinate of the vector and *dy* is the y-coordinate. The *dx* and *dy* values can be integer or float values. An example of a valid string is @”{3.0,2.5}”. The string is not localized, so items are always separated with a comma.

## Return Value

A Core Graphics structure that represents a two-dimensional vector. If the string is not well-formed, the function returns a vector whose dx and dy values are `0`.

## 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:)-4omzv) 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)