I'm trying to pass an action as a function into the .onEnded
modifier but when I attempt to, I get the following error:
Cannot convert value of type '() -> ()' to expected argument type '(LongPressGesture.Value) -> Void' (aka '(Bool) -> ()')
If I pass the function within a closure, it works just fine but I'm not a big fan of that because it takes up more space and I should just be able to pass it directly in to the modifier I would think.
// This works
LongPressGesture(minimumDuration: 0.25).onEnded {
startTimer()
}
// This throws the error.
LongPressGesture(minimumDuration: 0.25).onEnded(startTimer)
CodePudding user response:
You would need to change your startTimer
signature to accept LongPressGesture.Value
(which resolves to Bool
):
func startTimer(_ value : LongPressGesture.Value) {
//
}
LongPressGesture(minimumDuration: 0.25).onEnded(startTimer)