Your First iOS and SwiftUI App · Spacers and Padding | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4919757-your-first-ios-and-swiftui-app/lessons/16

I am seeing this error Reference to member 'default' cannot be resolved without a contextual type
Can you please spot the mistake

import SwiftUI

struct ContentView: View {

@State var alertIsVisible: Bool = false

var body: some View {
VStack {

           HStack {
               Text("Move the slider as close as possible to:");
               Text(" 100")
           }
           
           // Slider
           HStack{
               Text("1");
               Slider(value: .constant(10)
               Text("100")
           }
           
           Button(action: {
               print("Hello")
               self.alertIsVisible = true;
           }) {
               Text(/*@START_MENU_TOKEN@*/"Hit Me !!"/*@END_MENU_TOKEN@*/)
           }.alert(isPresented: $alertIsVisible){()-> Alert in
               return Alert(title: Text("Hello There"), message: Text("you have hit me"),dismissButton:.default(Text("Dismiss")) )
           }
           
           HStack{
               Button(){
                   Text("Start Over")
               }
               Text("Score");
               Text("99");
               
               Text("Round")
               Text("99")
               
               Button(){
                   Text("Info")
               }
           }
         
       }
}

}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView().previewLayout(.fixed(width: 896, height: 414))
}
}

Summary

This text will be hidden

Have you tried comparing your code to the final project you can find in the materials attached to his video?

I just tried the final project in the latest version of Xcode and it appears to run OK for me.

I can recreate the error, but I cannot figure out why the error comes. From the Bullseye Solution just add the Spacer() in the stack below:

// Score row
HStack {
Spacer() //<- This causes the error. Commenting it out makes the error disappear.
Button(action: {}) {
Text(“Start Over”)
}
Spacer()
Text(“Score:”)
Text(“(score)”)
Spacer()
Text(“Round:”)
Text(“999”)
Spacer()
Button(action: {}) {
Text(“Info”)
}

@cicosai @rhoffman19 Do you still have issues with this?