UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Xcode doesn't let me code...

Forums > 100 Days of SwiftUI

Hi guys,

when I'm trying to do the 1st challenge project->converter -> our first several lines are: Import Swift UI, -> Struct ContentView:View{

But my Xcode is showing the red warning "Type 'ContentView' does not conform to protocol 'View'", and doesn't show the iphone preview for me on the right side of the screen. Is anyone know what happened to it? When I did the project 1 "WeSplit", it worked fine.

Thanks a lot! you all have a good day!

Leona

2      

You need import SwiftUI, not import Swift UI

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello World")
    }
}

2      

Patrick is right that you need import SwiftUI.

Also the View protocol (EG the View after ContentView:) requires a var body: some View { } which also require you to have a View eg Text("Hello World") in it. See Patrick example

If you can not see the preview then you need to check that this is after the ContentView struct

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

If it is then click on Editor>Canvas then it should show after you click resume.

2      

thank you guys.

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.