In SwiftUI how can I assign variable in view?

Viewed 870

I have this code here (placed in a view):

if videoPos > 0.05 {
                    Text("It Worked Yay!")
                    playerPaused = false
                }

However, since "Type '()' cannot conform to 'View'" I am not sure how I can change the variable when videoPos is > 0.05.

This is videoPos: @Binding private(set) var videoPos: Double

How can I overcome this?

1 Answers

You can use onChange

}// End HStack
.onChange(of: videoPos, perform: { value in
    if value > 0.05 {
        playerPaused = false
    }
})

if iOS 13 supported then use combine

}// End HStack
.onReceive(Just(videoPos), perform: { value in
    if value > 0.05 {
        playerPaused = false
    }
})
import Combine
Related