<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSRulerView/trackMarker(_:withMouseEvent:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSRulerView(im)trackMarker:withMouseEvent:"
  },
  "title" : "trackMarker(_:withMouseEvent:)"
}
-->

# trackMarker(_:withMouseEvent:)

Tracks the mouse to add `aMarker` based on the initial mouse-down or mouse-dragged event `theEvent`.

```
func trackMarker(_ marker: NSRulerMarker, withMouseEvent event: NSEvent) -> Bool
```

## Discussion

Returns <doc://com.apple.documentation/documentation/Swift/true> if the receiver adds `aMarker`, <doc://com.apple.documentation/documentation/Swift/false> if it doesn’t. This method works by sending [`trackMouse(with:adding:)`](/documentation/AppKit/NSRulerMarker/trackMouse(with:adding:)) to `aMarker` with `theEvent` and <doc://com.apple.documentation/documentation/Swift/true> as arguments.

An application typically invokes this method in one of two cases. In the simpler case, the client view can implement [`NSRulerView`](/documentation/AppKit/NSRulerView) to invoke this method when the user presses the mouse button while the cursor is in the NSRulerView’s ruler area. This technique is appropriate when it’s clear what kind of marker will be added by clicking the ruler area. The second, more general, case involves the application providing a palette of different kinds of markers that can be dragged onto the ruler, from the ruler’s accessory view or from some other place. With this technique the palette tracks the cursor until it enters the ruler view, at which time it hands over control to the ruler view by invoking [`trackMarker(_:withMouseEvent:)`](/documentation/AppKit/NSRulerView/trackMarker(_:withMouseEvent:)).

---

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)