Xcode SwiftUI window not shown after successful build

167 Views Asked by At

I get the following warning, on main.storyboard

Unsupported Configuartion:
Window Controller requires a content view controller

This is the custom class linked to the Window Controller, which is also the StoryBoard Entry Point,


import Cocoa
import SwiftUI

class FirstWindowController: NSWindowController {
    
    override func windowDidLoad() {
        super.windowDidLoad()
        
        
        let contentView =  ContentView(myListModel: MyListModel())
            .environmentObject(UserData())
        
        
        self.window?.contentView = NSHostingView(rootView: contentView)
       
    }
   
}

This is inside the AppDelegate.swift which is annotated as @NSApplicationMain.

func applicationDidFinishLaunching(_ aNotification: Notification) {
      
       window = NSWindow(
           contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
            styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
            backing: .buffered, defer: false)
        window.center()
        window.setFrameAutosaveName("Main Window”)

}

The main.storyboard, AppDelegate.swift, and FirstWindowController.swift are identical to those of a project which was launching and showing the application window with no problem. I just renamed it to something else, and removed the Core Data support from the code. But in this project, the window doesn’t show up after successful build.

I also have checked and compared all the configuration of the storyboard for both of these projects. They seem to be totally identical.

Any help for fixing this would be appreciated.

1

There are 1 best solutions below

1
zmerr On BEST ANSWER

This might be due to a bug.

I removed all the other schemes but the one I was using in the project and the window is now loading.

Yet, the same warning is still there.