Browse Questions
- Use .onTapGesture for standard taps, and .onSimultaneousGesture when you need two gestures to fire together without one cancelling the other.
- A diffable data source is a data source that you drive with immutable snapshots of Hashable identifiers instead of index-path callbacks, and it computes the inserts, deletes, and moves for you.
- These protocols define how types support equality checks, hashing, and ordering.
- URLSession is Apple's networking API for HTTP requests.
Use .onTapGesture for standard taps, and .onSimultaneousGesture when you need two gestures to fire together without one cancelling the other.
Use .onTapGesture when:
- A button-like element (e.g., chat bubble, emoji button)
- Opening a bottom sheet
- Selecting an item from a list
- Toggling a state (expand/collapse)
Use .onSimultaneousGesture when:
- A scroll view needs a tap gesture (avoid losing scrolling)
- A draggable view that still detects taps
- A long press that shouldn't block taps
- Multi-gesture components (like a map: drag + tap markers)
// Standard tap — cancels scroll gesture
ScrollView {
Text("Hello")
.onTapGesture { print("tapped") } // blocks scroll in some cases
}
// Simultaneous — both gestures fire independently
ScrollView {
Text("Hello")
.onSimultaneousGesture(TapGesture().onEnded {
print("tapped without blocking scroll")
})
}
Common Misunderstanding:
.onSimultaneousGesture is not a replacement for .onTapGesture.
| Modifier | Purpose |
|---|---|
.onTapGesture | Detecting taps — exclusive, can cancel competing gestures |
.onSimultaneousGesture | Combining gestures without conflict — both fire at once |
Use
.onTapGestureby default. Only switch to.onSimultaneousGesturewhen you notice a parent gesture (likeScrollView) is being blocked.