Code below works fine even if optional type isn't what the .gesture() modifier really wants for its parameter type.
someKindOfView
.gesture(condition ? DragGesture() : nil)
Why is this possible?
Many thanks!!!!
CodePudding user response:
Because the Gesture is generic protocol...
and so the gesture modifier accepts generic type conforming to Gesture
and there is such extension confirming Optional to Gesture
so in case of
.gesture(condition ? DragGesture() : nil)
compiler infers type as .gesture(_ gesture: DragGesture?, ... and all works.



