You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xcode 15使用#Preview宏预览UIKit视图失败:FailedToLaunchAppError

Xcode 15中使用#Preview宏预览UIKit视图时出现FailedToLaunchAppError的解决办法

我在Xcode 15中尝试用#Preview宏预览UIKit视图,在iPhone 15模拟器上遇到了FailedToLaunchAppError,报错信息如下:

== PREVIEW UPDATE ERROR:

FailedToLaunchAppError: Failed to launch

==================================

|  RemoteHumanReadableError: The operation couldn’t be completed. Transaction failed. Process failed to launch. (process launch failed)
|  
|  BSTransactionError (1):
|  ==error-reason: process launch failed
|  ==transaction: <FBApplicationProcessLaunchTransaction: 0x600003b287e0>
|  ==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}}}}}
|  ==error-description: Process failed to launch.
|  ==NSLocalizedFailureReason: Transaction failed. Process failed to launch. (process launch failed)

测试代码如下:

import UIKit

final class SomeViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .red
    }
}

@available(iOS 17, *)
#Preview {
    SomeViewController()
}

可行的解决方法

  • 清理项目并重启Xcode
    执行Product > Clean Build Folder(快捷键Cmd+Shift+K),完全退出Xcode后重新打开项目尝试预览。
  • 重置模拟器
    打开iPhone 15模拟器,执行Device > Erase All Content and Settings,重置完成后重新运行预览。
  • 调整预览代码结构
    直接返回UIViewController可能触发启动异常,尝试用导航控制器包裹:
    @available(iOS 17, *)
    #Preview {
        UINavigationController(rootViewController: SomeViewController())
    }
    
  • 检查签名配置
    进入项目Signing & Capabilities页面,确认签名证书、配置文件无过期或配置错误问题。
  • 删除DerivedData文件夹
    手动删除路径~/Library/Developer/Xcode/DerivedData下的项目缓存文件,重启Xcode后重新构建项目。
  • 更新Xcode到稳定版
    若使用的是Xcode测试版,建议切换到最新稳定版,避免版本兼容性问题。

内容的提问来源于stack exchange,提问作者Max

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 20:57:47