Type 'MyApp' does not conform to protocol 'App'

Hello!

Newbie here learning Swift and tweaking a VisionOS app.

I am following Apple documentation to specify an initial window size. I have the following code in my ContentView.swift file:

@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .defaultSize(CGSize(width: 600, height: 400))
    }
}

When I build the project, I get the following 2 errors:

  1. Type 'MyApp' does not conform to protocol 'App' (line 2)
  2. 'Scene' is ambiguous for type lookup in this context (line 3)

Any tips on how I can resolve these?

Thank you.

Answered by pictureman in 782642022

I was able to get it to work by tweaking the code to the following (thank you 'lorem ipsum' over at Stack Overflow!)

Here's the corrected code:

struct GlimpseVision: App {
    var body: some SwiftUI.Scene {
        WindowGroup {
            ContentView()
        }
        .defaultSize(CGSize(width: 1000, height: 250))
    }
}

I have the following code in my ContentView.swift file: Is it really in ContentView file ? It should be in a MyApp file.

I tested by creating the same app. Here is the structure you should get when you create a VisionOS project (called My):

ContentView File is

import SwiftUI
import RealityKit
import RealityKitContent

struct ContentView: View {
    var body: some View {
        VStack {
            Model3D(named: "Scene", bundle: realityKitContentBundle)
                .padding(.bottom, 50)

            Text("Hello, world!")
        }
        .padding()
    }
}

#Preview(windowStyle: .automatic) {
    ContentView()
}
Accepted Answer

I was able to get it to work by tweaking the code to the following (thank you 'lorem ipsum' over at Stack Overflow!)

Here's the corrected code:

struct GlimpseVision: App {
    var body: some SwiftUI.Scene {
        WindowGroup {
            ContentView()
        }
        .defaultSize(CGSize(width: 1000, height: 250))
    }
}
Type 'MyApp' does not conform to protocol 'App'
 
 
Q