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

# addToolTip(_:owner:userData:)

Creates a tooltip for a defined area in the view and returns a tag that identifies the tooltip rectangle.

```
func addToolTip(_ rect: NSRect, owner: Any, userData data: UnsafeMutableRawPointer?) -> NSView.ToolTipTag
```

## Parameters

`rect`

A rectangle defining the region of the view to associate the tooltip with.

`owner`

An object from which to obtain the tooltip string. The object should either implement  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/view:stringForToolTip:point:userData:>, or return a suitable string from its <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/description> method. It can therefore simply be an <doc://com.apple.documentation/documentation/Foundation/NSString> object.
  
  > Important:
  > The view maintains a weak reference to `owner`. You’re responsible for ensuring that `owner` remains valid for as long as it may be needed.

`data`

Any additional information you want to pass to <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/view:stringForToolTip:point:userData:>; it isn’t used if `owner` doesn’t implement this method.

## Return Value

An integer tag identifying the tooltip; you can use this tag to remove the tooltip.

## Discussion

The tooltip string is obtained dynamically from `owner` by invoking either the `NSToolTipOwner` informal protocol method <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/view:stringForToolTip:point:userData:>, if implemented, or the <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol> protocol method <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/description>.

---

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)