SwiftUI SceneDelegate 问题
SwiftUI SceneDelegate Issue
在 SceneDelegate.swift
中,以下代码返回错误消息 "Use of unresolved identifier 'ContentView'; did you mean 'ContentMode'?"。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options
connectionOptions: UIScene.ConnectionOptions) {
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: ContentView())
self.window = window
window.makeKeyAndVisible()
}
此错误导致程序构建失败。令人惊讶的是,当我使用完全相同的 SceneDelegate.swift
创建一个新项目时,ContentView 没有问题。
如果我将 ContentView 更改为 ContentMode,它 returns 无法构造错误 'ContentMode',因为它没有可访问的初始值设定项。
还有其他人遇到过这个问题吗?只是好奇我应该从哪里开始寻找或者我做错了什么。
想通了这一点。如果有人好奇我更改了 ContentView.swift
文件名但没有在 SceneDelegate.swift
.
中更新它
因此,如果将 ContentView.swift
文件更改为 BetterNameView.swift
,则需要将 SceneDelegate.swift
中的上述代码从 ContentView()
更新为 BetterNameView()
在 SceneDelegate.swift
中,以下代码返回错误消息 "Use of unresolved identifier 'ContentView'; did you mean 'ContentMode'?"。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options
connectionOptions: UIScene.ConnectionOptions) {
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: ContentView())
self.window = window
window.makeKeyAndVisible()
}
此错误导致程序构建失败。令人惊讶的是,当我使用完全相同的 SceneDelegate.swift
创建一个新项目时,ContentView 没有问题。
如果我将 ContentView 更改为 ContentMode,它 returns 无法构造错误 'ContentMode',因为它没有可访问的初始值设定项。
还有其他人遇到过这个问题吗?只是好奇我应该从哪里开始寻找或者我做错了什么。
想通了这一点。如果有人好奇我更改了 ContentView.swift
文件名但没有在 SceneDelegate.swift
.
因此,如果将 ContentView.swift
文件更改为 BetterNameView.swift
,则需要将 SceneDelegate.swift
中的上述代码从 ContentView()
更新为 BetterNameView()