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

Swift中print函数无法输出到控制台的问题排查求助

Troubleshooting Missing print() Output in Xcode

Hey there! It's super frustrating when print() doesn't show up in the console even though you know the code is running. Let's walk through the most common fixes for this issue:

  • Double-check console filtering settings
    Even though you mentioned selecting "All Output", take a quick second to confirm:

    • The filter dropdown in the Xcode console is definitely set to All Output (not limited to a specific process or "Process" mode).
    • The search bar above the console is empty—accidental keywords can easily filter out your output without you noticing.
  • Check for OS_ACTIVITY_MODE in Scheme settings
    This is a super common culprit! If you ever added this environment variable to suppress noisy system logs, it might be blocking your own print() statements too:

    1. Go to Product > Scheme > Edit Scheme (or hit Cmd + <).
    2. Select the Run tab, then switch to the Arguments pane.
    3. Look in the Environment Variables section for OS_ACTIVITY_MODE. If it’s set to disable, delete the variable entirely or change its value to enable.
  • Test with NSLog as a fallback
    Temporarily swap your print() call with NSLog("viewDidLoad") and re-run the app. If NSLog shows up, you might have a custom print() implementation somewhere in your project that’s redirecting output away from the console.

  • Reset device/simulator connection

    • For physical devices: Unplug and re-plug your device, then make sure Xcode’s console is connected to the correct device (check the dropdown at the top of the Xcode window).
    • For simulators: Quit the simulator completely, restart it, and re-run your project. Simulators can sometimes get stuck and stop logging output unexpectedly.
  • Clean build files and restart Xcode
    Xcode’s cache can cause weird, unexplained glitches:

    1. Press Cmd + Shift + K to clean the project.
    2. Press Cmd + Option + Shift + K to delete the derived data folder.
    3. Quit Xcode entirely, then reopen and run your project again.

Just to confirm, your code itself looks totally correct:

override func viewDidLoad() {
    super.viewDidLoad()
    print("viewDidLoad")
}

Work through these steps one by one, and you should get your print() output back in no time!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:23:04