3

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?

4
  • Update playerPaused where you update videoPos. Commented Jun 25, 2021 at 13:08
  • I have pasted where I directly declare and set videoPos equal to another value, here: pastebin.com/9zVr6geB but it isn't inside of the same struct (VideoPlayerControlsView) but in another class, how can I edit it from there? Commented Jun 25, 2021 at 13:15
  • @EmilioPelaez If it helps here is all my code: pastebin.com/Ss6m0CA1 Commented Jun 25, 2021 at 13:15
  • You can use this }// Your view end .onChange(of: videoPos) { value in playerPaused = false } Commented Jun 25, 2021 at 13:17

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, I had spent so long trying to solve this :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.