---
title: "setEventHandler(_:andSelector:forEventClass:andEventID:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsappleeventmanager/seteventhandler(_:andselector:foreventclass:andeventid:)"
---

# setEventHandler(_:andSelector:forEventClass:andEventID:)

Registers the Apple event handler specified by handler for the event specified by eventClass and eventID.

## Declaration

```swift
func setEventHandler(_ handler: Any, andSelector handleEventSelector: Selector, forEventClass eventClass: AEEventClass, andEventID eventID: AEEventID)
```

## Discussion

Discussion If an event handler is already registered for the specified event class and event ID, removes it. The signature for handler should match the following: - (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent;

## See Also

### Working with event handlers

- [removeEventHandler(forEventClass:andEventID:)](foundation/nsappleeventmanager/removeeventhandler(foreventclass:andeventid:).md)
