<!--
{
  "availability" : [
    "iOS: 2.0.0 - 27.0.0",
    "iPadOS: 2.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.2.0 - 27.0.0",
    "tvOS: 9.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "CFNetwork",
  "identifier" : "/documentation/CFNetwork/CFNetServiceSetClient(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "CFNetwork"
    ],
    "preciseIdentifier" : "c:@F@CFNetServiceSetClient"
  },
  "title" : "CFNetServiceSetClient(_:_:_:)"
}
-->

# CFNetServiceSetClient(_:_:_:)

Associates a callback function with a CFNetService or disassociates a callback function from a CFNetService.

```
func CFNetServiceSetClient(_ theService: CFNetService, _ clientCB: CFNetServiceClientCallBack?, _ clientContext: UnsafeMutablePointer<CFNetServiceClientContext>?) -> Bool
```

## Parameters

`theService`

The CFNetService; cannot be `NULL`.

`clientCB`

The callback function that is to be associated with this CFNetService. If you are shutting down the service, set `clientCB` to `NULL` to disassociate from this CFNetService the callback function that was previously associated.

`clientContext`

Context information to be used when `clientCB` is called; cannot be `NULL`.

## Return Value

`TRUE` if the client was set; otherwise, `FALSE`.

## Discussion

The callback function specified by `clientCB` will be called to report IP addresses (in the case of [`CFNetServiceResolve`](/documentation/CFNetwork/CFNetServiceResolve)) or to report registration errors (in the case of [`CFNetServiceRegister`](/documentation/CFNetwork/CFNetServiceRegister)).

### Special Considerations

This function is thread safe.

For a CFNetService that will operate asynchronously, call this function and then call [`CFNetServiceScheduleWithRunLoop(_:_:_:)`](/documentation/CFNetwork/CFNetServiceScheduleWithRunLoop(_:_:_:)) to schedule the service on a run loop. Then call [`CFNetServiceRegister`](/documentation/CFNetwork/CFNetServiceRegister) or [`CFNetServiceResolve`](/documentation/CFNetwork/CFNetServiceResolve).

---

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)