我正在尝试在自定义框架中编写SwiftUI视图。
之所以这样做是因为我想隐藏子视图的实现,因为Swift没有提供命名空间。因此,我做了一个子框架,并在其中实现了测试视图。
所以我想做
Calendar
)然后我得到了
ContentView
的预览但是问题是:
Calendar
内部),并显示以下错误:
'Cell_Previews' is not a member type of 'Calendar'
----------------------------------------
BuildError: Failed to build Cell.swift
Compiling failed: 'Cell_Previews' is not a member type of 'Calendar'
failedToBuildDylib: /Users/q/Library/Developer/Xcode/DerivedData/singleview-cmqdlfabgiintkgnvdpzzagojvzf/Build/Intermediates.noindex/Previews/singleview/Intermediates.noindex/Calendar.build/Debug-iphonesimulator/Calendar.build/Objects-normal/x86_64/Cell.2.preview-thunk.swift:22:36: error: 'Cell_Previews' is not a member type of 'Calendar'
typealias Cell_Previews = Calendar.Cell_Previews
~~~~~~~~ ^
/Users/q/Library/Developer/Xcode/DerivedData/singleview-cmqdlfabgiintkgnvdpzzagojvzf/Build/Intermediates.noindex/Previews/singleview/Intermediates.noindex/Calendar.build/Debug-iphonesimulator/Calendar.build/Objects-normal/x86_64/Cell.2.preview-thunk.swift:6:6: error: replaced accessor for 'previews' could not be found
@_dynamicReplacement(for: previews) private static var __preview__previews: some View {
^
/Users/q/Library/Developer/Xcode/DerivedData/singleview-cmqdlfabgiintkgnvdpzzagojvzf/Build/Intermediates.noindex/Previews/singleview/Intermediates.noindex/Calendar.build/Debug-iphonesimulator/Calendar.build/Objects-normal/x86_64/Cell.2.preview-thunk.swift:21:27: error: 'Cell' is not a member type of 'Calendar'
typealias Cell = Calendar.Cell
~~~~~~~~ ^
/Users/q/Library/Developer/Xcode/DerivedData/singleview-cmqdlfabgiintkgnvdpzzagojvzf/Build/Intermediates.noindex/Previews/singleview/Intermediates.noindex/Calendar.build/Debug-iphonesimulator/Calendar.build/Objects-normal/x86_64/Cell.2.preview-thunk.swift:14:6: error: replaced accessor for 'body' could not be found
@_dynamicReplacement(for: body) private var __preview__body: some View {
^
那么,如果我想查看预览,该怎么办?
这是该项目的屏幕截图
这是失败的屏幕截图
我正在使用Xcode 11.2.1(11B500)。
谢谢!
编辑:谢谢克里斯! Cell.swift(在框架内部)的代码是:
import SwiftUI
public struct Cell: View {
public init() {}
public var body: some View {
Text("INTERNAL")
}
}
public struct Cell_Previews: PreviewProvider {
public init() {}
public static var previews: some View {
Cell()
}
}
ContentView.swift(框架的用户)为:
import SwiftUI
import Calendar
struct ContentView: View {
var body: some View {
Cell()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}