---
title: "addToolTip(_:owner:userData:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsview/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.

## Declaration

```swift
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

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

## Discussion

Discussion The tooltip string is obtained dynamically from owner by invoking either the NSToolTipOwner informal protocol method view:stringForToolTip:point:userData:, if implemented, or the NSObjectProtocol protocol method description.

## See Also

### Providing a Tool Tip

- [toolTip](appkit/nsview/tooltip.md)
- [removeAllToolTips()](appkit/nsview/removealltooltips().md)
- [removeToolTip(_:)](appkit/nsview/removetooltip(_:).md)
- [NSView.ToolTipTag](appkit/nsview/tooltiptag.md)
