首页 > 解决方案 > SwiftUI 预览画布未显示

问题描述

我有一个运行 iOS 13.0 的项目,它由一个包含所有视图的框架(Common)和一个使用该框架显示 UI 的应用程序目标组成。该项目本身构建良好。

当我想在 RatingView.swift 中实现预览时,画布视图会显示Failed to build RatingView.swift'RatingView' is not a member type of 'Common'。我做这样的预览:

#if DEBUG
import SwiftUI
struct RatingViewRepresentable: UIViewRepresentable {
    func makeUIView(context: Context) -> UIView {
        return RatingView()
    }
    func updateUIView(_ view: UIView, context: Context) {}
}

struct RatingView_Preview: PreviewProvider {
    static var previews: some View {
        RatingViewRepresentable()
    }
}
#endif

标签: swiftswiftuipreview

解决方案


推荐阅读