<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTrackingArea/init(rect:options:owner:userInfo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTrackingArea(im)initWithRect:options:owner:userInfo:"
  },
  "title" : "init(rect:options:owner:userInfo:)"
}
-->

# init(rect:options:owner:userInfo:)

Initializes and returns an object defining a region of a view to receive mouse-tracking events, mouse-moved events, cursor-update events, or possibly all these events.

```
init(rect: NSRect, options: NSTrackingArea.Options = [], owner: Any?, userInfo: [AnyHashable : Any]? = nil)
```

## Parameters

`rect`

A rectangle that defines a region of a target view, in the view’s coordinate system, for tracking events related to mouse tracking and cursor updating. The specified rectangle should not exceed the view’s bounds rectangle.

`options`

One or more constants that specify the type of tracking area, the situations when the area is active, and special behaviors of the tracking area. See the description of [`NSTrackingArea.Options`](/documentation/AppKit/NSTrackingArea/Options-swift.struct) and related constants for details. You must specify one or more options for the initialized object for the type of tracking area and for when the tracking area is active; zero is not a valid value.

`owner`

The object to receive the requested mouse-tracking, mouse-moved, or cursor-update messages. It does not necessarily have to be the view associated with the created `NSTrackingArea` object, but should be an object capable of responding to the `NSResponder` methods [`mouseEntered(with:)`](/documentation/AppKit/NSResponder/mouseEntered(with:)), [`mouseExited(with:)`](/documentation/AppKit/NSResponder/mouseExited(with:)), [`mouseMoved(with:)`](/documentation/AppKit/NSResponder/mouseMoved(with:)), and [`cursorUpdate(with:)`](/documentation/AppKit/NSResponder/cursorUpdate(with:)).

`userInfo`

A dictionary containing arbitrary data for each mouse-entered, mouse-exited, and cursor-update event. When handling such an event you can obtain the dictionary by sending [`userData`](/documentation/AppKit/NSEvent/userData) to the `NSEvent` object. (The dictionary is not available for mouse-moved events.) This parameter may be `nil`.

## Return Value

The newly-initialized tracking area object.

## Discussion

After creating and initializing an `NSTrackingArea` object with this method, you must add it to a target view using the [`addTrackingArea(_:)`](/documentation/AppKit/NSView/addTrackingArea(_:)) method. When changes in the view require changes in the geometry of its tracking areas, the Application Kit invokes [`updateTrackingAreas()`](/documentation/AppKit/NSView/updateTrackingAreas()). The view should implement this method to replace the current `NSTrackingArea` object with one with a recomputed area.

### Special Considerations

Beginning with OS X v10.5, the [`init(rect:options:owner:userInfo:)`](/documentation/AppKit/NSTrackingArea/init(rect:options:owner:userInfo:)), along with the [`addTrackingArea(_:)`](/documentation/AppKit/NSView/addTrackingArea(_:)) method of `NSView`, replace the `NSView` method [`addTrackingRect(_:owner:userData:assumeInside:)`](/documentation/AppKit/NSView/addTrackingRect(_:owner:userData:assumeInside:)).

## See Also

[`userInfo`](/documentation/AppKit/NSTrackingArea/userInfo)

The dictionary containing the data associated with the receiver when it was created.

[`rect`](/documentation/AppKit/NSTrackingArea/rect)

The rectangle defining the area encompassed by the receiver.

[`owner`](/documentation/AppKit/NSTrackingArea/owner)

The object owning the receiver, which is the recipient of mouse-tracking, mouse-movement, and cursor-update messages.

[`options`](/documentation/AppKit/NSTrackingArea/options-swift.property)

The options specified for the receiver.

[`NSTrackingArea`](/documentation/AppKit/NSTrackingArea)

A region of a view that generates mouse-tracking and cursor-update events when the pointer is over that region.



---

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)