---
title: "init(eventRef:)"
framework: appkit
role: symbol
role_heading: Initializer
path: "appkit/nsevent/init(eventref:)"
---

# init(eventRef:)

Creates and returns a new event object for a Carbon event.

## Declaration

```swift
init?(eventRef: UnsafeRawPointer)
```

## Parameters

- `eventRef`: The EventRef opaque type to be associated with the created NSEvent object.

## Return Value

Return Value An autoreleased NSEvent object corresponding to eventRef or nil if eventRef cannot be converted into an equivalent NSEvent object.

## Discussion

Discussion This method is valid for all events. The created NSEvent object retains the EventRef object and is released when the NSEvent object is freed.

## See Also

### Related Documentation

- [eventRef](appkit/nsevent/eventref.md)

### Creating an event object

- [keyEvent(with:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifiers:isARepeat:keyCode:)](appkit/nsevent/keyevent(with:location:modifierflags:timestamp:windownumber:context:characters:charactersignoringmodifiers:isarepeat:keycode:).md)
- [mouseEvent(with:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:)](appkit/nsevent/mouseevent(with:location:modifierflags:timestamp:windownumber:context:eventnumber:clickcount:pressure:).md)
- [enterExitEvent(with:location:modifierFlags:timestamp:windowNumber:context:eventNumber:trackingNumber:userData:)](appkit/nsevent/enterexitevent(with:location:modifierflags:timestamp:windownumber:context:eventnumber:trackingnumber:userdata:).md)
- [otherEvent(with:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:)](appkit/nsevent/otherevent(with:location:modifierflags:timestamp:windownumber:context:subtype:data1:data2:).md)
- [init(cgEvent:)](appkit/nsevent/init(cgevent:)-4igjn.md)
