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

# lineBreakByHyphenating(before:within:)

Returns the index of the closest character before the specified index, and within the specified range, that can fit on a new line by hyphenating.

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

## Parameters

`location`

The location 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 by hyphenating. Returns `NSNotFound` if no line break by hyphenation is possible before `index`.

## Discussion

In other words, during text layout, finds the appropriate line break by hyphenation (the character index at which the hyphen glyph should be inserted) when the character at `index` won’t fit on the same line as the character at the beginning of `aRange`.

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)