---
title: "lineBreak(before:within:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsattributedstring/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.

## Declaration

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

## Parameters

- `location`: The index in the attributed string.
- `aRange`: The range.

## Return Value

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

Discussion Raises an rangeException if index or any part of aRange lies beyond the end of the receiver’s characters.

## See Also

### Calculating linguistic units

- [doubleClick(at:)](foundation/nsattributedstring/doubleclick(at:).md)
- [lineBreakByHyphenating(before:within:)](foundation/nsattributedstring/linebreakbyhyphenating(before:within:).md)
- [nextWord(from:forward:)](foundation/nsattributedstring/nextword(from:forward:).md)
