我有一个带有三个目标的 iOS SwiftUI 应用程序 - 一个应用程序目标和 2 个静态库(如下所示)
Project Workspace
--AppTarget
----(some files)
--EntryPoint (static library)
---- <Struct conforming to App protocol>.swift
---- AppDelegate.swift
---- (other files)
--Experience (static library)
---- ContentView.swift
---- (other files)
Run Code Online (Sandbox Code Playgroud)
由于某些原因,层次结构定义如下:
// AppTarget depends on EntryPoint and Experience
AppTarget -> EntryPoint, Experience
// Experience depends on EntryPoint
Experience -> EntryPoint
Run Code Online (Sandbox Code Playgroud)
EntryPoint 库具有应用程序的入口点,即符合应用程序协议的结构体。body 属性必须是一个 Scene,其中必须包含一个 View。问题是,View 是在 Experience 中定义的...并且因为 Experience 依赖于 EntryPoint,所以我无法将 Experience 标记为 EntryPoint 的依赖项并执行以下操作
import Experience
Run Code Online (Sandbox Code Playgroud)
在 EntryPoint 目标中,因为这会导致循环依赖错误。
SwiftUI 期望场景内的视图在编译时已知。
问题:
@main
public struct ProjectApp: App {
@UIApplicationDelegateAdaptor
private var appDelegate: AppDelegate
public var body: some Scene {
WindowGroup {
ContentView() // ERROR
}
}
public init() {
}
}
Run Code Online (Sandbox Code Playgroud)
ContentView 在 Experience 中定义,但我无法导入 Experience,因为它是一个更高的库。据我所知,Swift 中没有外部声明或前向声明。
| 归档时间: |
|
| 查看次数: |
57 次 |
| 最近记录: |