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

# rulerView(_:willAdd:atLocation:)

Returns a potentially modified location to which the marker should be added.

```
func rulerView(_ ruler: NSRulerView, willAdd marker: NSRulerMarker, atLocation location: CGFloat) -> CGFloat
```

## Parameters

`ruler`

The ruler view sending the message.

`marker`

The marker to be added.

`location`

The new location for the marker, in the ruler view’s coordinates.

## Return Value

The modified location to which the marker should be added.

## Discussion

This method ensures that the proposed `location` of `aMarker` lies within the appropriate bounds for the receiver’s text container, returning the modified location. Appropriate bounds are those of the text container minus its line fragment padding.

Typically, the ruler view’s width matches that of its text view.

---

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)