无法从Cocoapods渲染SwiftUI预览

时间:2019-11-28 00:35:56

标签: ios swift cocoapods swiftui

我在一个自带的公用库中有一个SwiftUI结构。

public struct NTextField: View {
    public var body: some View {
        Text("Hello, World!")
    }

    public init() {

    }
}

struct NTextField_Previews: PreviewProvider {
    static var previews: some View {
        NTextField()
    }
}

我单击文件后,所见即所得预览无法加载

enter image description here

点击“诊断”时,我会看到类似这样的内容:

Error Domain=com.apple.dt.UITestingAgent Code=-1 "failed to load library at path "/Users/<my_app_name>/Library/Developer/Xcode/DerivedData/<my_app_name>/Build/Intermediates.noindex/Previews/<my_app_name>/Products/Debug-iphonesimulator/<my_custom_pod>/<my_custom_pod>.framework/<my_custom_pod>": Library not loaded: 

有什么想法吗?我删除了衍生数据,进行了清理和构建。

还找到了this on the cocoapods git hub issue tracker

1 个答案:

答案 0 :(得分:1)

您可以尝试将其添加到Podfile中(由JamesHurstcltnschlosserandersio建议)

class Pod::Target::BuildSettings::AggregateTargetSettings
    alias_method :ld_runpath_search_paths_original, :ld_runpath_search_paths

    def ld_runpath_search_paths
        return ld_runpath_search_paths_original unless configuration_name == "Debug"
        return ld_runpath_search_paths_original + framework_search_paths
    end
end

class Pod::Target::BuildSettings::PodTargetSettings
    alias_method :ld_runpath_search_paths_original, :ld_runpath_search_paths

    def ld_runpath_search_paths
        return (ld_runpath_search_paths_original || []) + framework_search_paths
    end
end