Xcode 15 UIKit Preview FailedToLaunchAppError:无法启动错误

Max*_*Max 6 preview uikit ios swift xcode15

我尝试在 Xcode 15 中使用 #Preview 宏预览 UIKit 视图,但出现此错误

\n
== PREVIEW UPDATE ERROR:\n\n    FailedToLaunchAppError: Failed to launch\n    \n    ==================================\n    \n    |  RemoteHumanReadableError: The operation couldn\xe2\x80\x99t be completed. Transaction failed. Process failed to launch. (process launch failed)\n    |  \n    |  BSTransactionError (1):\n    |  ==error-reason: process launch failed\n    |  ==transaction: <FBApplicationProcessLaunchTransaction: 0x600003b287e0>\n    |  ==precipitating-error: Error Domain=FBProcessExit Code=64 "The process failed to launch." UserInfo={NSLocalizedFailureReason=The process failed to launch., BSErrorCodeDescription=launch-failed, NSUnderlyingError=0x600000c1ad90 {Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x600000c1aee0 {Error Domain=NSPOSIXErrorDomain Code=111 "Unknown error: 111" UserInfo={NSLocalizedDescription=Launchd job spawn failed}}}}}\n    |  ==error-description: Process failed to launch.\n    |  ==NSLocalizedFailureReason: Transaction failed. Process failed to launch. (process launch failed)\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试在 iPhone 15 上预览的代码

\n
import UIKit\n\nfinal class SomeViewController: UIViewController {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        view.backgroundColor = .red\n    }\n}\n\n@available(iOS 17, *)\n#Preview {\n    SomeViewController()\n}\n
Run Code Online (Sandbox Code Playgroud)\n

小智 7

我们的项目最初无法使用Apple Silicon中的模拟器进行调试,因此无法预览。

\n

从每个目标中排除 arm64 架构后:\n在此输入图像描述\n模拟器可以工作,但是#Preview仍然无法工作,并给出与您的问题相同的错误消息:无法启动(我很确定我们得到了完全相同的错误)。

\n

尝试了各种方法后:

\n
    \n
  • 删除didFinishLaunch中的所有代码
  • \n
  • 删除预览缓存
  • \n
  • 删除模拟器缓存
  • \n
  • 删除派生数据
  • \n
  • 重新启动 Xcode
  • \n
  • 重新启动Mac
  • \n
\n

全部失败\xef\xbc\x8c直到我们记住如何使用 Rosetta 模拟器构建应用程序:\n在此输入图像描述

\n

使用Rosetta模拟器作为构建目标并将预览设置为同一设备,奇迹发生了\xef\xbc\x9a\n在此输入图像描述

\n

对我们来说,重要的是:\n我们关闭了自动刷新画布以使预览最终正常工作。\n在此输入图像描述

\n