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

Xcode Playground运行一直显示‘Running’无输出,新手求助排查问题

Troubleshooting Your Stuck Xcode Playground (UI Content Not Showing)

Hey there! As someone who’s been there with finicky Playgrounds, let’s walk through the most likely reasons your project’s stuck on "Running" and not displaying any UI, especially since you’re working from that older (but awesome) blog post:

1. You haven’t set up the Live View properly

Playgrounds don’t automatically show UI content—you need to tell it to! Here’s what to check:

  • First, make sure your Playground is targeting iOS: Click the File Inspector (right sidebar, top icon that looks like a page), scroll to Playground Settings, and set Platform to iOS.
  • Then, enable the Live View: Look for the little eye icon in the bottom-right corner of the editor and click it. This opens the panel where your UI should appear.

2. Your code isn’t linking to the Playground’s live view container

Even if you’ve built all the custom views/ViewControllers from the blog, Playground has no idea which one to display unless you explicitly set it. You’ll need to import the PlaygroundSupport framework and hook up your UI:

import PlaygroundSupport
import UIKit

// Replace this with your custom view or ViewController from the blog
let mainView = YourCustomView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
// OR if you're using a ViewController:
// let vc = YourCustomViewController()
// vc.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480)

// This is the magic line that tells Playground to show your UI
PlaygroundPage.current.liveView = mainView
// PlaygroundPage.current.liveView = vc

If the blog post didn’t include this step (common in older posts), that’s probably the main issue!

3. There’s a hidden infinite loop or main thread block

Double-check your code for any unintended infinite loops (like a while true without a break condition) or synchronous blocking operations (like a network call run directly on the main thread). These will lock up the Playground and keep it stuck on "Running".

4. Xcode’s cache is acting up

Sometimes Xcode’s temporary files get corrupted, causing weird Playground behavior. Try these quick fixes:

  • Go to Product > Clean Build Folder (hold Option to see this if "Clean" is there instead)
  • Quit and restart Xcode entirely
  • If that still doesn’t work, delete the Derived Data folder: Go to Xcode > Settings > Locations, click the arrow next to Derived Data, and delete the folder for your Playground.

5. Outdated API issues (since the blog is from 2015)

Even if you fixed obvious errors, some older Swift/UIKit APIs from 2015 are now deprecated or work differently. For example:

  • UIGraphicsBeginImageContext should be replaced with UIGraphicsImageRenderer
  • Some Swift syntax (like function parameters, optional handling) has changed over versions
  • Check for any red error indicators you might have missed, or use Xcode’s Fix-It suggestions (click the yellow/red dots) to update deprecated code.

Hopefully one of these fixes gets your UI showing up! Playgrounds can be quirky at first, but once you get the hang of the setup, they’re great for experimenting.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 04:33:29