Playground App 无法将类型“LLAppDelegateProxy”的值转换为“SwiftUI.AppDelegate”

问题描述 投票:0回答:1

我的 playground 应用程序因这个错误而崩溃。不确定发生了什么或如何解决这个

Thread 1: signal SIGABRT

@main
    struct PlaygroundApp: App {
        @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate: AppDelegate
    
        var body: some Scene {
            WindowGroup {
                ContentView()
            }
        }
    }
    
    public class AppDelegate: NSObject, UIApplicationDelegate {
        static var orientationLock: UIInterfaceOrientationMask = .all
    
        public func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
            AppDelegate.orientationLock
        }
    }
swift swiftui appdelegate sigabrt
1个回答
0
投票

func body
App
应该返回
some Scene
,而不是
some View
,例如

var body: some Scene {
    WindowGroup {
        ContentView()
    }
}

如果你尝试在 Xcode 中编译你会得到更好的错误信息:

Candidate 不能推断'Body' = 'some View' 因为'some View' 不是标称类型所以不符合'Scene'

© www.soinside.com 2019 - 2024. All rights reserved.