---
title: "CFNetServiceMonitorCreate(_:_:_:_:)"
framework: cfnetwork
role: symbol
role_heading: Function
path: "cfnetwork/cfnetservicemonitorcreate(_:_:_:_:)"
---

# CFNetServiceMonitorCreate(_:_:_:_:)

Creates an instance of a NetServiceMonitor object that watches for record changes.

## Declaration

```swift
func CFNetServiceMonitorCreate(_ alloc: CFAllocator?, _ theService: CFNetService, _ clientCB: CFNetServiceMonitorClientCallBack, _ clientContext: UnsafeMutablePointer<CFNetServiceClientContext>) -> Unmanaged<CFNetServiceMonitor>
```

## Parameters

- `alloc`: The allocator to use to allocate memory for the new object. Pass NULL or doc://com.apple.documentation/documentation/CoreFoundation/kCFAllocatorDefault to use the current default allocator.
- `theService`: CFNetService to be monitored.
- `clientCB`: Pointer to callback function that is to be called when a record associated with theService changes; cannot be NULL.
- `clientContext`: Pointer to user-defined contextual information that is to be passed to the callback specified by clientCB when the callback is called; cannot be NULL. For details, see doc://com.apple.cfnetwork/documentation/CFNetwork/CFNetServiceClientContext.

## Return Value

Return Value A new instance of a CFNetServiceMonitor, or NULL if the monitor could not be created. Ownership follows the The Create Rule.

## Discussion

Discussion This function creates a CFNetServiceMonitor that watches for changes in records associated with theService. If the CFNetServiceMonitor is to run in asynchronous mode, call CFNetServiceMonitorScheduleWithRunLoop(_:_:_:) to schedule the monitor on a run loop. Then call CFNetServiceMonitorStart(_:_:_:) to start monitoring. When a change occurs, the callback function specified by clientCB will be called. For details, see CFNetServiceMonitorClientCallBack. If the CFNetServiceMonitor is to run in synchronous mode, call CFNetServiceMonitorStart(_:_:_:). To stop a monitor that is running in asynchronous mode, call CFNetServiceMonitorStop(_:_:) and CFNetServiceMonitorUnscheduleFromRunLoop(_:_:_:). To stop a monitor that is running in synchronous mode, call CFNetServiceMonitorStop(_:_:). If you no longer need to monitor record changes, call CFNetServiceMonitorStop(_:_:) to stop the monitor and then call CFNetServiceMonitorInvalidate(_:)to invalidate the monitor so it cannot be used again. Then call CFRelease to release the memory associated with CFNetServiceMonitorRef. Special Considerations This function is thread safe.

## See Also

### Network Services

- [CFNetService](cfnetwork/cfnetservice.md)
- [CFNetServiceBrowser](cfnetwork/cfnetservicebrowser.md)
- [CFNetServiceBrowserFlags](cfnetwork/cfnetservicebrowserflags.md)
- [CFNetServiceMonitor](cfnetwork/cfnetservicemonitor.md)
- [CFNetServiceMonitorType](cfnetwork/cfnetservicemonitortype.md)
- [CFNetServiceClientContext](cfnetwork/cfnetserviceclientcontext.md)
- [CFNetServiceRegisterFlags](cfnetwork/cfnetserviceregisterflags.md)
- [CFNetServicesError](cfnetwork/cfnetserviceserror.md)
- [CFNetServiceBrowserInvalidate(_:)](cfnetwork/cfnetservicebrowserinvalidate(_:).md)
- [CFNetServiceBrowserScheduleWithRunLoop(_:_:_:)](cfnetwork/cfnetservicebrowserschedulewithrunloop(_:_:_:).md)
- [CFNetServiceBrowserCreate(_:_:_:)](cfnetwork/cfnetservicebrowsercreate(_:_:_:).md)
- [CFNetServiceBrowserGetTypeID()](cfnetwork/cfnetservicebrowsergettypeid().md)
- [CFNetServiceBrowserSearchForDomains(_:_:_:)](cfnetwork/cfnetservicebrowsersearchfordomains(_:_:_:).md)
- [CFNetServiceBrowserSearchForServices(_:_:_:_:)](cfnetwork/cfnetservicebrowsersearchforservices(_:_:_:_:).md)
- [CFNetServiceBrowserStopSearch(_:_:)](cfnetwork/cfnetservicebrowserstopsearch(_:_:).md)
