---
title: "DNSServiceAddRecord(_:_:_:_:_:_:_:)"
framework: dnssd
role: symbol
role_heading: Function
path: "dnssd/dnsserviceaddrecord(_:_:_:_:_:_:_:)"
---

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

Adds a record to a registered service.

## Declaration

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

## Parameters

- `sdRef`: A DNSServiceRef initialized by doc://com.apple.dnssd/documentation/dnssd/DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:).
- `RecordRef`: A pointer to an uninitialized DNSRecordRef. Upon succesfull completion of this call, this ref may be passed to doc://com.apple.dnssd/documentation/dnssd/DNSServiceUpdateRecord(_:_:_:_:_:_:) or doc://com.apple.dnssd/documentation/dnssd/DNSServiceRemoveRecord(_:_:_:). If the above DNSServiceRef is passed to doc://com.apple.dnssd/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

Return Value Returns kDNSServiceErr_NoError on success, otherwise returns an error code indicating the error that occurred (the RecordRef is not initialized).

## Discussion

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(_:_:_:_:_:_:) or 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.

## See Also

### Service Registration

- [DNSServiceRegister(_:_:_:_:_:_:_:_:_:_:_:_:)](dnssd/dnsserviceregister(_:_:_:_:_:_:_:_:_:_:_:_:).md)
- [DNSServiceRemoveRecord(_:_:_:)](dnssd/dnsserviceremoverecord(_:_:_:).md)
- [DNSServiceUpdateRecord(_:_:_:_:_:_:)](dnssd/dnsserviceupdaterecord(_:_:_:_:_:_:).md)
