Thursday, October 29, 2026
HomeiOS Developmentios - Not ready to make use of the Toggle Swap with...

ios – Not ready to make use of the Toggle Swap with if else situations in swift ui

[ad_1]

I’m not in a position to entry use the change. I would like if the change is on, it ought to provide you with a textual content area and whether it is off the worth of the variable must be zero. Can anybody assist me with this. I’ve tried to make use of two completely different strategies. One by utilizing .OnAppear and one with out utilizing .OnAppear. Once I use .OnAppear, it comes up with a waning that the results of textual content area is unused. And after I do not use .onAppear it does not settle for (userSettings.load = 0) however the textual content area works advantageous then. I do not perceive what I’m doing flawed right here.The variables are outlined as :

              @Printed var loadingrate = Float() // That is outlined in one other file as an Setting.
              @State var casualloading: Bool = false //That is outlined on the identical file

                  Toggle("load", isOn: $load)
                  
                       .onChange(of: load)
                   {
                       worth in
               
        if load == false
                       {
                           userSettings.loadrate = 0
                      
                       }
                     
               else
               {
                  TextField(" load", worth: $userSettings.loadrate, format: .quantity).   //Results of 'TextField<Label>' initializer is unused
                  
                            
               }}

With out utilizing .onAppear

              Toggle("load", isOn: $load) //Kind '()' can't conform to 'View'
          if (load == false)
         { //Kind '()' can't conform to 'View'
               userSettings.loadrate = 0

                    } //Kind '()' can't conform to 'View'
              
        else
        {
            TextField("Load", worth: $userSettings.loadrate, format: .quantity)
        }}


          


                   
              

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments