我的 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
}
}
func body
的App
应该返回some Scene
,而不是some View
,例如
var body: some Scene {
WindowGroup {
ContentView()
}
}
如果你尝试在 Xcode 中编译你会得到更好的错误信息:
Candidate 不能推断'Body' = 'some View' 因为'some View' 不是标称类型所以不符合'Scene'