---
title: "ancestorShared(with:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsview/ancestorshared(with:)"
---

# ancestorShared(with:)

Returns the closest ancestor shared by the view and another specified view.

## Declaration

```swift
func ancestorShared(with view: NSView) -> NSView?
```

## Parameters

- `view`: Another view to test for closest shared ancestor with the view.

## Return Value

Return Value The closest ancestor or nil if there’s no such object. Returns self if aView is identical to the view.

## See Also

### Getting the Related Objects

- [superview](appkit/nsview/superview.md)
- [subviews](appkit/nsview/subviews.md)
- [window](appkit/nsview/window.md)
- [opaqueAncestor](appkit/nsview/opaqueancestor.md)
- [isDescendant(of:)](appkit/nsview/isdescendant(of:).md)
- [enclosingMenuItem](appkit/nsview/enclosingmenuitem.md)
- [enclosingScrollView](appkit/nsview/enclosingscrollview.md)
