<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: -",
    "macOS: 10.10.0 -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/DispatchSourceProtocol/setEventHandler(handler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "s:So18OS_dispatch_sourceP8DispatchE15setEventHandler7handleryAC0D8WorkItemC_tF"
  },
  "title" : "setEventHandler(handler:)"
}
-->

# setEventHandler(handler:)

Sets the event handler work item for the dispatch source.

```
func setEventHandler(handler: DispatchWorkItem)
```

## Parameters

`handler`

The event handler block to submit to the source’s target queue.

## Discussion

The event handler (if specified) is submitted to the source’s target queue in response to the arrival of an event.

---

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)