what is the difference between hitTest(_:with:) and hitTest:withEvent:

Asked on 2025-10-30

1 search

The question about the difference between hitTest(_:with:) and hitTest:withEvent: is not directly covered in the provided context from the WWDC sessions. However, I can provide some general information about these methods based on typical usage in iOS development.

In UIKit, hitTest(_:with:) is a method used to determine which view should receive a touch event. It is called on a view to find the deepest subview that contains a specified point. The method hitTest:withEvent: is an older Objective-C method that serves a similar purpose, allowing you to determine the view that should handle a touch event.

The main difference between these two is the language and API evolution context. hitTest(_:with:) is the Swift version, while hitTest:withEvent: is the Objective-C version. Both are used to manage touch events in a view hierarchy, but the Swift version is more modern and aligns with Swift's language features and conventions.

If you have any questions about the content presented by Apple at WWDC, feel free to ask!