<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSRectFromString(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@F@NSRectFromString"
  },
  "title" : "NSRectFromString(_:)"
}
-->

# NSRectFromString(_:)

Returns a rectangle from a text-based representation.

```
func NSRectFromString(_ aString: String) -> NSRect
```

## Discussion

Scans `aString` for four numbers which are used as the x and y coordinates and the width and height, in that order, to create an NSPoint object. If `aString` does not contain four numbers, those numbers that were scanned are used, and 0 is used for the remaining values. If `aString` does not contain any numbers, this function returns an NSRect object with a rectangle whose origin is (0, 0) and width and height are both 0.

---

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)