<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "dnssd",
  "identifier" : "/documentation/dnssd/TXTRecordGetItemAtIndex(_:_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "dnssd"
    ],
    "preciseIdentifier" : "c:@F@TXTRecordGetItemAtIndex"
  },
  "title" : "TXTRecordGetItemAtIndex(_:_:_:_:_:_:_:)"
}
-->

# TXTRecordGetItemAtIndex(_:_:_:_:_:_:_:)

Allows you to retrieve a key name and value pointer, given an index into a TXT Record.

```
func TXTRecordGetItemAtIndex(_ txtLen: UInt16, _ txtRecord: UnsafeRawPointer!, _ itemIndex: UInt16, _ keyBufLen: UInt16, _ key: UnsafeMutablePointer<CChar>!, _ valueLen: UnsafeMutablePointer<UInt8>!, _ value: UnsafeMutablePointer<UnsafeRawPointer?>!) -> DNSServiceErrorType
```

## Parameters

`txtLen`

The size of the received TXT Record.

`txtRecord`

Pointer to the received TXT Record bytes.

`itemIndex`

An index into the TXT Record.

`keyBufLen`

The size of the string buffer being supplied.

`key`

A string buffer used to store the key name. On return, the buffer contains a null-terminated C string giving the key name. DNS-SD TXT keys are usually 9 characters or fewer. To hold the maximum possible key name, the buffer should be 256 bytes long.

`valueLen`

On output, will be set to the size of the “value” data.

`value`

On output, *value is set to point to location within TXT Record bytes that holds the value data.

## Return Value

Returns [`kDNSServiceErr_NoError`](/documentation/dnssd/kDNSServiceErr_NoError) on success. Returns kDNSServiceErr_NoMemory if keyBufLen is too short. Returns kDNSServiceErr_Invalid if index is greater than TXTRecordGetCount()-1.

## Discussion

Legal index values range from zero to TXTRecordGetCount()-1. It’s also possible to iterate through keys in a TXT record by simply calling TXTRecordGetItemAtIndex() repeatedly, beginning with index zero and increasing until TXTRecordGetItemAtIndex() returns kDNSServiceErr_Invalid.

On return:

For keys with no value, *value is set to NULL and *valueLen is zero.

For keys with empty value, *value is non-NULL and *valueLen is zero.

For keys with non-empty value, *value is non-NULL and *valueLen is non-zero.

---

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)