---
title: "cgVector(for:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nscoder/cgvector(for:)"
---

# cgVector(for:)

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

## Declaration

```swift
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

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

Discussion In general, you should use this function only to convert strings that were previously created using the string(for:) function.

## See Also

### Representing Geometric Types as Strings

- [cgAffineTransform(for:)](foundation/nscoder/cgaffinetransform(for:).md)
- [cgPoint(for:)](foundation/nscoder/cgpoint(for:).md)
- [cgRect(for:)](foundation/nscoder/cgrect(for:).md)
- [cgSize(for:)](foundation/nscoder/cgsize(for:).md)
- [nsDirectionalEdgeInsets(for:)](foundation/nscoder/nsdirectionaledgeinsets(for:).md)
- [uiEdgeInsets(for:)](foundation/nscoder/uiedgeinsets(for:).md)
- [uiOffset(for:)](foundation/nscoder/uioffset(for:).md)
- [string(for:)](foundation/nscoder/string(for:)-4qz0a.md)
- [string(for:)](foundation/nscoder/string(for:)-4omzv.md)
- [string(for:)](foundation/nscoder/string(for:)-6yx6n.md)
- [string(for:)](foundation/nscoder/string(for:)-6ix86.md)
- [string(for:)](foundation/nscoder/string(for:)-2f1xb.md)
- [string(for:)](foundation/nscoder/string(for:)-hp8b.md)
- [string(for:)](foundation/nscoder/string(for:)-26b4z.md)
- [string(for:)](foundation/nscoder/string(for:)-454dj.md)
