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

# nextWord(from:forward:)

Returns the index of the first character of the word after or before the specified index.

```
func nextWord(from location: Int, forward isForward: Bool) -> Int
```

## Parameters

`location`

The index in the attribute string.

`isForward`

<doc://com.apple.documentation/documentation/Swift/true> if the search should be forward, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if this is the first character after `index` that begins a word; if `flag` is <doc://com.apple.documentation/documentation/Swift/false>, it’s the first character before `index` that begins a word, whether `index` is located within a word or not.

## Discussion

If `index` lies at either end of the string and the search direction would progress past that end, it’s returned unchanged.

This method is intended for moving the insertion point during editing, not for linguistic analysis or parsing of text.

Raises an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) if `index` 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)