---
title: "enumerateNeighbors(for:maximumCount:distanceType:using:)"
framework: naturallanguage
role: symbol
role_heading: Instance Method
path: "naturallanguage/nlembedding/enumerateneighbors(for:maximumcount:distancetype:using:)-6dy4x"
---

# enumerateNeighbors(for:maximumCount:distanceType:using:)

Passes the nearest strings of a location in the vocabulary space to a closure.

## Declaration

```swift
@nonobjc func enumerateNeighbors(for vector: [Double], maximumCount maxCount: Int, distanceType: NLDistanceType = .cosine, using block: (String, NLDistance) -> Bool)
```

## Parameters

- `vector`: A location in the vocabulary space.
- `maxCount`: The largest number of times the method calls block.
- `distanceType`: A means of calculating distance that determines which formula the method uses to evaluate a neighbor’s distance from vector.
- `block`: A closure with the following parameters: The closure returns a Boolean that indicates whether to stop enumerating neighbors.

## See Also

### Finding strings and their distances in an embedding

- [neighbors(for:maximumCount:distanceType:)](naturallanguage/nlembedding/neighbors(for:maximumcount:distancetype:)-8f1jc.md)
- [neighbors(for:maximumCount:distanceType:)](naturallanguage/nlembedding/neighbors(for:maximumcount:distancetype:)-8lp4z.md)
- [enumerateNeighbors(for:maximumCount:distanceType:using:)](naturallanguage/nlembedding/enumerateneighbors(for:maximumcount:distancetype:using:)-72jda.md)
- [distance(between:and:distanceType:)](naturallanguage/nlembedding/distance(between:and:distancetype:).md)
- [NLDistance](naturallanguage/nldistance.md)
