|
I'm a complete beginner, I am following the 100 days of SwiftUI but as someone with zero experience it's slow going. I am trying to put what I have learned into practice which helps me to remember at least parts of what I am learning. But I am stuck on what I feel should be a pretty simple task. I have a function that makes a random paragraph out of some arrays. It generates the paragraph on load, but I wanted a button to create a new paragraph when pressed. Below is my code, could someone point me in the right direction?
|
|
can you please try below code - in SwiftUI , the button click will not change any thing , our mind thinks like it should , but here the compiler want a source of truth to change , which is a property wrapper in your case
then i toggle it on button click, so it become true, then inside body i check it like so So in short - first click , becomes true, then on second click become false , but you still get a new para as you are now calling your random function, on third click becomes true ,so function is called again and the cycle continues
|
|
As @AmritShirvastava has indicated, you need an
|
|
Thank you, I'm going to resist the tempation to copy and paste but will look at these and try and learn from them! |
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.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.