0

I'm a beginner (started a week ago) in SwiftUI and trying out different things with app development. I'm stuck with Zstack not being able to execute anything. This is multiplatform app, and when I simulate it, it's just blank white space. When I erase zstack, and just run with vstack, it does the same thing.

What's the problem here?

Andrew
  • 26,706
  • 9
  • 85
  • 101

1 Answers1

1

It looks like you have created an app that is not based on SwiftUI but based on UIKit.

When creating your app make sure that you choose the following options:

  • Interface: SwiftUI
  • Life Cycle: SwiftUI App

enter image description here

Then looking in the Project Navigator you should see something like this:

enter image description here

You should then put your SwiftUI code inside the ContentView.swift

struct ContentView: View {
    var body: some View {
        ZStack {
            VStack {
                LinearGradient(
                    gradient: Gradient(colors: [.green, .white, .blue]),
                    startPoint: .topLeading,
                    endPoint: .bottomTrailing
                )
                .edgesIgnoringSafeArea(.all)
            }

        }
    }
}

Which would give you something like this:

enter image description here

If you are a beginner with SwiftUI then I suggest that you look at some tutorials, hackingwithswift.com is a good place to start.

Andrew
  • 26,706
  • 9
  • 85
  • 101