If else question

Why do I get error:

"Cannot convert value of type ‘(Double) → some View’ to expected argument type ‘Double’ "

with this code in one of the tutorials:

@Environment(\.colorScheme) var colorScheme
     .
     .
           if colorScheme == .dark {
              let opacity = 0.1}
           else {
              let opacity = 0.3}

when i use above with:

              [Color("RingsColor").opacity(opacity)

but the tutorial code works

                 let opacity = colorScheme == .dark ? 0.1 : 0.3

This topic was automatically closed after 166 days. New replies are no longer allowed.