带有框架的模块化应用程序中的 Swift UI 预览

Eug*_*e P 6 swiftui swiftui-previews

在我的框架内运行SwiftUI视图预览时遇到问题。\n这是一个项目结构。在此输入图像描述

\n

主目标(ContentViewGradientView)中的 SwiftUI 视图预览按预期工作。

\n

但是,当我\xe2\x80\x99m 尝试预览UI.xcodeprojectSwiftUIView )内的视图时,我\xe2\x80\x99m 收到错误

\n

在此输入图像描述

\n
PotentialCrashError: Update failed\n\nXCPreviewAgent may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application.\n\n==================================\n\n|  RemoteHumanReadableError\n|  \n|  LoadingError: failed to load library at path "/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib": Optional(dlopen(/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib, 0x0002): tried: \'/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Products/Debug-iphonesimulator/SwiftUIView.1.preview-thunk.dylib\' (errno=2), \'/Applications/Xcode_14.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib\' (errno=2), \'/Users/yevgeniy/Library/Developer/Xcode/DerivedData/Hackathon-abjguuvpzyisdncwvpeguazdifiu/Build/Intermediates.noindex/Previews/Hackathon/Intermediates.noindex/UI.build/Debug-iphonesimulator/UI.build/Objects-normal/x86_64/SwiftUIView.1.preview-thunk.dylib\' (mach-o file, but is an incompatible architecture (have \'x86_64\', need \'arm64\')))\n|  \n|  ==================================\n|  \n|  |  MessageSendFailure: Message send failure for <ServiceMessage 115: update>\n
Run Code Online (Sandbox Code Playgroud)\n

~/Library/Logs/DiagnosticReports 文件夹为空。

\n

Rosetta模式下使用Xcode 14.0

\n

Rosetta模式下的Xcode 14.1 - 同样的问题

\n

没有 Rosetta 的相同配置也可以正常工作。(在我的产品项目中,由于第 3 方依赖,我必须使用 Rosetta)

\n

为活动架构构建设置为NO

\n

为 Active 架构构建不会YES改变任何内容

\n

所有常见的事情都尝试过:

\n
    \n
  • 重建项目
  • \n
  • 干净的派生数据
  • \n
  • ETC。
  • \n
\n
\n
The answer to those who came here with the same problem: \n\nIf you have to run in **Rosetta** mode, keep checking this post.\n\nOtherwise, run without **Rosetta**, that will solve your problem.\n
Run Code Online (Sandbox Code Playgroud)\n
\n

dre*_*kka 0

我遇到了同样的问题。基于 M1Pro 构建,未安装 Rosetta。iOS 项目。预览工作正常,然后在我移动一些代码以适应所需的应用程序结构(不是我的)后的一天停止了。预览错误指示一个特定的 swift 源文件,但当我将其复制到另一个项目时,它完美地编译和预览。