<!--
{
  "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/DNSServiceAddRecord(_:_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "dnssd"
    ],
    "preciseIdentifier" : "c:@F@DNSServiceAddRecord"
  },
  "title" : "DNSServiceAddRecord(_:_:_:_:_:_:_:)"
}
-->

# DNSServiceAddRecord(_:_:_:_:_:_:_:)

Adds a record to a registered service.

```
func DNSServiceAddRecord(_ sdRef: DNSServiceRef!, _ RecordRef: UnsafeMutablePointer<DNSRecordRef?>!, _ flags: DNSServiceFlags, _ rrtype: UInt16, _ rdlen: UInt16, _ rdata: UnsafeRawPointer!, _ ttl: UInt32) -> DNSServiceErrorType
```

## Parameters

`sdRef`

A DNSServiceRef initialized by [`DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:)).

`RecordRef`

A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this call, this ref may be passed to [`DNSServiceUpdateRecord(_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceUpdateRecord(_:_:_:_:_:_:)) or [`DNSServiceRemoveRecord(_:_:_:)`](/documentation/dnssd/DNSServiceRemoveRecord(_:_:_:)). If the above DNSServiceRef is passed to [`DNSServiceRefDeallocate(_:)`](/documentation/dnssd/DNSServiceRefDeallocate(_:)), RecordRef is also invalidated and may not be used further.

`flags`

Currently ignored, reserved for future use.

`rrtype`

The type of the record (e.g. kDNSServiceType_TXT, kDNSServiceType_SRV, and so on).

`rdlen`

The length, in bytes, of the rdata.

`rdata`

The raw rdata to be contained in the added resource record.

`ttl`

The time to live of the resource record, in seconds. Most clients should pass 0 to indicate that the system should select a sensible default value.

## Return Value

Returns [`kDNSServiceErr_NoError`](/documentation/dnssd/kDNSServiceErr_NoError) on success, otherwise returns an error code indicating the error that occurred (the RecordRef is not initialized).

## Discussion

The name of the record will be the same as the registered service’s name. The record can later be updated or deregistered by passing the RecordRef initialized by this function to [`DNSServiceUpdateRecord(_:_:_:_:_:_:)`](/documentation/dnssd/DNSServiceUpdateRecord(_:_:_:_:_:_:)) or [`DNSServiceRemoveRecord(_:_:_:)`](/documentation/dnssd/DNSServiceRemoveRecord(_:_:_:)).

Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe with respect to a single DNSServiceRef. If you plan to have multiple threads in your program simultaneously add, update, or remove records from the same DNSServiceRef, then it’s the caller’s responsibility to use a mutext lock or take similar appropriate precautions to serialize those calls.

---

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)