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

# ancestorShared(with:)

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

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

## Parameters

`view`

Another view to test for closest shared ancestor with the view.

## Return Value

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

## Discussion

---

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)