<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CALayer/hitTest(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CALayer(im)hitTest:"
  },
  "title" : "hitTest(_:)"
}
-->

# hitTest(_:)

Returns the farthest descendant of the receiver in the layer hierarchy (including itself) that contains the specified point.

```
func hitTest(_ p: CGPoint) -> CALayer?
```

## Parameters

`p`

A point in the coordinate system of the receiver’s superlayer.

## Return Value

The layer that contains `thePoint` or `nil` if the point lies outside the receiver’s bounds rectangle.

## 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)