Damiano Miazzi
Damiano Miazzi

Reputation: 2305

The compiler is unable to type-check this expression in reasonable time

in my ScrollView i'm try to display the forecast received from internet request. The server if there is no data available for that specific item example windGust the default values is set to "0" (string)

Now on my ScrollView I want to hide the Text that contain zero, in order to show only the forecast item that have value.

so I put in my Group the if else state to check if display the Text or not, but if I put more than 3 if else state I get the warning 'The compiler is unable to type-check this expression in reasonable time'

I have 10 var to be display if the have value.. how can I show or hide if this have value different than "0"

 Group{
        if forecast.change_indicator == "0" {
            Text(forecast.change_indicator).hidden()
        } else {
              Text(forecast.change_indicator)
        }

        if forecast.showTimeBecoming == "0" {
       Text(forecast.change_indicator).hidden()
        } else {
         Text(forecast.showTimeBecoming)
        }
      if forecast.windGust == "0" {
       Text(forecast. windGust).hidden()
        } else {
         Text(forecast. windGust)
        }
   }



Upvotes: 1

Views: 367

Answers (1)

Asperi
Asperi

Reputation: 257493

Try to separate them into own properties, so top Group contain only results, like below

var ChangeIndicator : some View {
    Group {
        if forecast.change_indicator == "0" {
            Text(forecast.change_indicator).hidden()
        } else {
            Text(forecast.change_indicator)
        }
    }
}

var ShowTimeBecoming : some View {
    Group {
        if forecast.showTimeBecoming == "0" {
            Text(forecast.showTimeBecoming).hidden()
        } else {
            Text(forecast.showTimeBecoming)
        }
    }
}
// ... << declare similar for each entity

and resulting

Group {
   ChangeIndicator
   ShowTimeBecoming
   // ... << all others follow
}

Upvotes: 1

Related Questions