UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How do I make an if statement always look for change in a variable?

Forums > SwiftUI

I was playing around with having multiple views and wanted to make a picker in a different view change the look of another view. if I change the variable from 1 to 2 it does change the gradient. However using the picker does not change the gradient.

https://imgur.com/V3pUQDW

https://imgur.com/1dqczTp

3      

+1 for asking a great question in the Forums.

-1 for not copy/ pasting code into your message. If we want to test your code, you expect us to retype the whole thing?

To answer your question, you need to move beyond @State and learn about Bindings.

Here's a great video from @twostraws: Building Custom Component with Bindings

Code Example:

// Please use the code block to add code examples.
let plea = "Please use the code block to list code examples."

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.