---
title: "distance(between:and:distanceType:)"
framework: naturallanguage
role: symbol
role_heading: Instance Method
path: "naturallanguage/nlembedding/distance(between:and:distancetype:)"
---

# distance(between:and:distanceType:)

Calculates the distance between two strings in the vocabulary space.

## Declaration

```swift
@nonobjc func distance(between firstString: String, and secondString: String, distanceType: NLDistanceType = .cosine) -> NLDistance
```

## Parameters

- `firstString`: A string in the embedding vocabulary.
- `secondString`: Another string in the embedding vocabulary.
- `distanceType`: A means of calculating distance that determines which formula the method uses to evaluate the distance between firstString and secondString.

## Return Value

Return Value The distance associated with distanceType.

## 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)
- [enumerateNeighbors(for:maximumCount:distanceType:using:)](naturallanguage/nlembedding/enumerateneighbors(for:maximumcount:distancetype:using:)-6dy4x.md)
- [NLDistance](naturallanguage/nldistance.md)
