我試圖將一個動作作為函式傳遞給.onEnded修飾符,但是當我嘗試時,我收到以下錯誤:
Cannot convert value of type '() -> ()' to expected argument type '(LongPressGesture.Value) -> Void' (aka '(Bool) -> ()')
如果我在閉包中傳遞函式,它作業得很好,但我不喜歡它,因為它占用更多空間,我應該能夠將它直接傳遞給我認為的修飾符。
// This works
LongPressGesture(minimumDuration: 0.25).onEnded {
startTimer()
}
// This throws the error.
LongPressGesture(minimumDuration: 0.25).onEnded(startTimer)
uj5u.com熱心網友回復:
您需要更改您的startTimer簽名以接受LongPressGesture.Value(決議為Bool):
func startTimer(_ value : LongPressGesture.Value) {
//
}
LongPressGesture(minimumDuration: 0.25).onEnded(startTimer)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/346661.html
