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!!!!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.