<!--
{
  "availability" : [
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedString/lineBreak(before:within:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAttributedString(im)lineBreakBeforeIndex:withinRange:"
  },
  "title" : "lineBreak(before:within:)"
}
-->

# lineBreak(before:within:)

Returns the appropriate line break when the character at the index doesn’t fit on the same line as the character at the beginning of the range.

```
func lineBreak(before location: Int, within aRange: NSRange) -> Int
```

## Parameters

`location`

The index in the attributed string.

`aRange`

The range.

## Return Value


Returns the index of the closest character before `index` within `aRange`, that can be placed on a new line when laying out text. Returns `NSNotFound` if no line break is possible before `index`.

## Discussion

Raises an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) if `index` or any part of `aRange` lies beyond the end of the receiver’s characters.

---

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)