# Keys

> USearch for Swift

A key is sixteen opaque bytes, rendered as a lowercase dashed UUID.
Integer identities park in the low eight bytes, so `Key(42)` prints as `00000000-0000-0000-0000-00000000002a` and an integer literal is a key wherever one is expected.
Keys need not be unique: several entries may share one, and `count(key:)` reports how many.

A key is `Codable` as that same string, so a document written by any SDK reads back here unchanged.

```swift
let key: Key = 42
assert(key.integerIdentity == 42)
let parsed = try Key(parsing: key.description)                             // equal to `key`
let encoded = String(decoding: try JSONEncoder().encode(key), as: UTF8.self) // "\"\(key)\""
```

`import USearch`

## Key

A 128-bit entry identity, most significant byte first, rendered as a lowercase dashed UUID.

```swift
struct Key
```

Keys need not be unique: several entries may share one, and `DenseIndex.count(key:)`
reports how many. Integer identities park in the low eight bytes, so `Key(42)`
prints as `00000000-0000-0000-0000-00000000002a`.

Conforms to: `Hashable`, `Comparable`, `CustomStringConvertible`, `ExpressibleByIntegerLiteral`, `Sendable`, `Equatable`, `Decodable`, `Encodable`

## nilKey

The all-zero key.

```swift
static let nilKey: Key
```

## init

Builds the all-zero key.

```swift
init()
```

```swift
init(_ value: UInt64)
```

Parks an integer identity in the low eight bytes, zeroing the rest.

```swift
init(integerLiteral value: UInt64)
```

```swift
init(bytes: [UInt8]) throws(USearchError)
```

Adopts sixteen bytes, most significant first.

```swift
init(parsing text: String) throws(USearchError)
```

Reads the rendering [`description`](https://www.unum.cloud/docs/usearch/swift/errors.md#description) produces.

```swift
init(from decoder: any Decoder) throws
```

Reads the key from the lowercase dashed rendering [`description`](https://www.unum.cloud/docs/usearch/swift/errors.md#description) produces.

## byteArray

The sixteen identity bytes, most significant first.

```swift
var byteArray: [UInt8] { get }
```

## integerIdentity

The integer identity in the low eight bytes, and nil when the high eight carry anything.

```swift
var integerIdentity: UInt64? { get }
```

## description

```swift
var description: String { get }
```

## *

```swift
func hash(into hasher: inout Hasher)
```

- `hash`
- `==`
- `<`

## encode

Writes the key as that same rendering.

```swift
func encode(to encoder: any Encoder) throws
```

