Search code examples
textswiftui

How can I solve "No exact matches in call to initializer" error when I am using Text in SwiftUI?


I just started with SwiftUI and have basic questions. I try to show the value of the rotation in the Text field. The error message I get is: "No exact matches in call to initializer"

Where is the mistake?

import SwiftUI

struct ContentView: View {

@State var rotation: Double = 0

var body: some View {

    VStack {

        VStack {

        Text("Hello, world!")
            .padding()
            
            Slider(value: $rotation, in: 0 ... 360, step: 0.1)
                .padding()

            Text(rotation)
              
        }
    }
}

}




struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Solution

  • and for fun you can also try this:

    struct ContentView: View {
        @State var rotation: Double = 0
        
        var body: some View {
                VStack {
                    Text("Hello, world!").rotationEffect(Angle(degrees: rotation)).padding()
                    Slider(value: $rotation, in: 0 ... 360, step: 0.1).padding()
                    Text("\(rotation)")
                }
        }
    }