"App' is ambiguous for type lookup in this context." 在 swiftui 项目中导入 Realm 时出现此错误

"App' is ambiguous for type lookup in this context." Getting this error while importing Realm in swiftui project

 import SwiftUI
 import RealmSwift

 @main
 struct RealmUpdatedDemoApp: App {
     var body: some Scene {
         WindowGroup {
             ContentView()            
         }
     }
 }

在主应用程序文件上导入 RealmSwift 时,我收到此错误,但在其他文件上没有。

这是名称冲突的情况,如果要在此 class 中导入 RealmSwift,请为 App 显式指定命名空间 SwiftUI

示例:

import SwiftUI
import RealmSwift

@main
struct SwiftUITestApp: SwiftUI.App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}