简体   繁体   English

Xcode playground 卡在“Running playground”或“Launching simulator”上,无法运行代码,怎么办?

[英]Xcode playground gets stuck on 'Running playground' or 'Launching simulator' and won't run the code, what to do?

Every time I create a new playground in order to test some code, Xcode gets stuck and won't run the code.每次我创建一个新的 playground 以测试一些代码时,Xcode 都会卡住并且不会运行代码。 It simply presents 'Running playground' or 'Launching simulator' statement at the top of the screen with the loading icon promisingly spinning next to it but nothing happens.它只是在屏幕顶部显示“Running playground”或“Launching simulator”语句,旁边有一个正在旋转的加载图标,但没有任何反应。 Sometimes this continues indefinitely and sometimes Xcode halts and prints this to console:有时这会无限期地持续下去,有时 Xcode 会停止并将其打印到控制台:

Playground execution failed: error: Couldn't lookup symbols:
__swift_FORCE_LOAD_$_swiftCoreImage 
__swift_FORCE_LOAD_$_swiftFoundation 
_playground_log_hidden 
_playground_logger_initialize 
_playground_log_postprint 

thread #1: tid = 0xc0cd0, 0x000000010ea7c3c0 MyPlayground`executePlayground, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2

frame #0: 0x000000010ea7c3c0 MyPlayground`executePlayground
frame #1: 0x000000010ea7b9c0 MyPlayground`__37-[XCPAppDelegate enqueueRunLoopBlock]_block_invoke + 32 
frame #2: 0x000000010f59625c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
frame #3: 0x000000010f57b304 CoreFoundation`__CFRunLoopDoBlocks + 356
frame #4: 0x000000010f57aa75 CoreFoundation`__CFRunLoopRun + 901
frame #5: 0x000000010f57a494 CoreFoundation`CFRunLoopRunSpecific + 420
frame #6: 0x0000000114985a6f GraphicsServices`GSEventRunModal + 161
frame #7: 0x0000000110124f34 UIKit`UIApplicationMain + 159
frame #8: 0x000000010ea7b6e9 MyPlayground`main + 201
frame #9: 0x0000000112ad268d libdyld.dylib`start + 1
frame #10: 0x0000000112ad268d libdyld.dylib`start + 1

I am running Xcode 8.0 (8A218a) on macOS Sierra 10.12.我在 macOS Sierra 10.12 上运行 Xcode 8.0 (8A218a)。

Hardware :硬件
MacBook Pro (13" Mid-2012) MacBook Pro(13" 2012 年中)
2,5 GHz Intel Core i5 2.5 GHz 英特尔酷睿 i5
4 GB 1600 MHz Ram DDR3 4 GB 1600 兆赫内存 DDR3

I have looked around but at least neither of these threads have provided an answer:我环顾四周,但至少这些线程都没有提供答案:
https://forums.developer.apple.com/thread/5902 https://forums.developer.apple.com/thread/5902
https://github.com/jas/playground/issues/9 https://github.com/jas/playground/issues/9

Things I have already tried with zero success:我已经尝试过零成功的事情:

  • Restarting Xcode重启 Xcode
  • Reinstalling Xcode (downgraded to 7.3 but since that didn't help I upgraded back to 8.0)重新安装 Xcode(降级到 7.3 但因为那没有帮助我升级回 8.0)
  • Restarting the machine重启机器
  • Creating a new playground创造一个新的游乐场

Do you have any ideas on how to solve this problem?你对如何解决这个问题有什么想法吗? I am new to programming and eagerly trying to learn Swift but Xcode is making it practically impossible.我是编程新手,急切地想学习 Swift,但 Xcode 使它几乎不可能。

Ans.答。 Switch to macOS platform切换到 macOS 平台

When you create a Playground, by default it select iOS platform and automatically imports UIKit.创建 Playground 时,默认选择 iOS 平台并自动导入 UIKit。 It's the UIKit which crashes and stuck all the time .是 UIKit 一直崩溃和卡住 If your (practice) code does not use UIKit then you can switch to MacOS platform .如果您的(练习)代码不使用 UIKit,那么您可以切换到 MacOS 平台 As major (not exact though) difference between iOS and macOS is in APPKit and UIKit. iOS 和 macOS 之间的主要(虽然不完全)区别在于 APPKit 和 UIKit。

In the upper right corner of your Xcode Playground, click on show/hide Utilities--> file inspector --> Playground Setting--> Platform--> macOS在 Xcode Playground 的右上角,单击 show/hide Utilities--> 文件检查器 --> Playground Setting--> Platform--> macOS

See screenShot below:请参阅下面的屏幕截图: 在此处输入图片说明

I have tried the following and it worked for me:我尝试了以下方法,它对我有用:

  1. press on the bottom "stop playground" button按下底部的“停止游乐场”按钮
  2. remove the first comment line and make import statement the first line.删除第一个注释行并使 import 语句成为第一行。 no space above import.导入上方没有空格。
  3. press execute button按执行按钮

In my case, Xcode 8.3.2, it works when I try as steps below:在我的情况下,Xcode 8.3.2,当我尝试以下步骤时它可以工作:

  1. File -> Close "Name.playground"文件 -> 关闭“Name.playground”
  2. File -> Close Playground文件 -> 关闭 Playground
  3. Quit Xcode退出 Xcode
  4. Re-open Xcode重新打开Xcode

Buggy Simulator's main process is still working even after Xcode closing.即使在 Xcode 关闭后,Buggy Simulator 的主进程仍在运行。 So here're the steps:所以这里是步骤:

  1. Quit Xcode;退出 Xcode;
  2. Kill com.apple.CoreSimulator.CoreSimulatorService process in Activity Monitor;在活动监视器中杀死com.apple.CoreSimulator.CoreSimulatorService进程;
  3. Launch Xcode and run your Playground.启动 Xcode 并运行您的 Playground。

In my experience, you should:根据我的经验,你应该:

  1. Prevent Swift playground refresh, by holding: the ► arrow at the bottom left part of the Playground and selecting "Manually Run"通过按住 Playground 左下角的 ► 箭头并选择“手动运行”来防止 Swift 游乐场刷新
  2. Quit Xcode退出 Xcode
  3. Restart Xcode重启Xcode

It works very well.它运作良好。

I have cancelled the comment on the first line.我已经取消了第一行的评论。 It solved for me.它为我解决了。 Make sure to try it after you have closed and relaunched Xcode and force quit com.apple.coresimulator from Activity Monitor确保在关闭并重新启动 Xcode 并从 Activity Monitor 强制退出 com.apple.coresimulator 后尝试它

添加 import PlaygroundSupport 为我解决了这个问题:)

You can switch to manual processing.您可以切换到手动处理。 It worked for me.它对我有用。 截图

Make sure you kill xcode in the activity monitor before eventually killing com.apple.CoreSimulator.CoreSimulatorService process in the activity monitor.在最终杀死活动监视器中的com.apple.CoreSimulator.CoreSimulatorService进程之前,请确保在活动监视器中杀死 xcode。 I tried killing the process a number of times and I realized if xcode is still running in the background activity then the com.apple.CoreSimulator.CoreSimulatorService process would pop up again even when you just killed it.我多次尝试终止该进程,我意识到如果 xcode 仍在后台活动中运行,那么即使您刚刚杀死它, com.apple.CoreSimulator.CoreSimulatorService进程也会再次弹出。

I had the same problem, all that I did is to open Assistance editor and everything works fine with me even when I closed the Assistance editor!我遇到了同样的问题,我所做的只是打开辅助编辑器,即使我关闭了辅助编辑器,一切正常! Don't ask why it was trial and error.不要问为什么这是反复试验。 Hope this will help you希望这会帮助你

I'm using Xcode 10.2 and am getting the same issue.我正在使用 Xcode 10.2 并且遇到了同样的问题。 So generally just use Online Swift Playground所以一般只使用Online Swift Playground

This serves my purposes!这符合我的目的! :-) :-)

In my case the problem was user-induced.在我的情况下,问题是用户引起的。 I had the assistant editor displayed, but the live view wasn't selected.我显示了助理编辑器,但没有选择实时视图。 Make sure it looks like this:确保它看起来像这样:

实时查看

And not like this:而不是这样:

在此处输入图片说明

After beating my head on this for a few hours, I realized I had accidentally deleted this, VERY MUCH important line that allows to test UIKit elements before committing my playground onto git:经过几个小时的思考,我意识到我不小心删除了这条非常重要的行,它允许在将我的操场提交到 git 之前测试 UIKit 元素:

// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()

Facepalm.面掌。 Hopefully this can help someone from pulling their hair out for a few hours.希望这可以帮助某人将头发拉出几个小时。

For me, the issue was the fact that MyPlayground was syncing to iCloud .对我来说,问题在于MyPlayground 正在同步到 iCloud Xcode saves your files every few seconds, and it leads to "not responding" states. Xcode 每隔几秒钟保存一次您的文件,这会导致“无响应”状态。

So there is a simple solution- just go to:所以有一个简单的解决方案 - 只需转到:

System Preferences - Apple ID - Apps on this Mac using iCloud- iCloud Drive - Options- And then uncheck "Playground"系统偏好设置 - Apple ID - 此 Mac 上使用 iCloud 的应用程序 - iCloud Drive - 选项 - 然后取消选中“游乐场”

That little trick helps to solve frozen "Running".这个小技巧有助于解决冻结的“跑步”。

防止 Playgrounds 同步

XCode 12.3 and still same issue happens. XCode 12.3仍然发生同样的问题。

Solution for me is Command + Q ( restart the Xcode )对我来说解决方案是 Command + Q(重新启动 Xcode)

运行一段时间后,您将看到错误消息,然后转到查看>调试区域>激活控制台,然后再次播放对我有用

Check for iCloud storage plan!检查 iCloud 存储空间计划!

If you do have one, it constantly syncs the entire computer which includes Desktop and Document folders.如果您有,它会不断同步整个计算机,包括桌面和文档文件夹。 Instead try creating a "Local Files" folder in your Home folder(command+shift+h) and keep your Playground projects there, where it doesn't sync to iCloud.而是尝试在您的主文件夹中创建一个“本地文件”文件夹(command+shift+h)并将您的 Playground 项目保留在那里,它不会同步到 iCloud。

This worked for me.I hope this works for you as well!这对我有用。我希望这对你也有用! :) :)

I deleted derived data and clean build folder.我删除了派生数据并清理了构建文件夹。 This works for me.这对我有用。 I was facing with Xcode 11.2.1 and Xcode 10.1 on same machine.我在同一台机器上遇到了 Xcode 11.2.1 和 Xcode 10.1。

也会发生,就像在我的情况下,当你定义了一个函数,但忘记调用它时?

As if this question didn't have enough answers, I will provide my "solution" to the stuck Swift playgrounds problem:好像这个问题没有足够的答案,我将为卡住的 Swift playgrounds 问题提供我的“解决方案”:

The one solution I've come across which works nicely for me (so I do not have to restart Xcode):我遇到的一种解决方案对我来说效果很好(所以我不必重新启动 Xcode):

killall launchd_sim

This will cause the spinning "Running Playground..." to go away and you can trigger a new execution.这将导致旋转的“Running Playground...”消失,您可以触发新的执行。 Be aware: the next execution is going to spin up launchd_sim and all those child processes again.请注意:下一次执行将再次启动launchd_sim和所有这些子进程。 It would probably be best to kill only the relevant child process.最好只杀死相关的子进程。 But I didn't find it so far.但我至今没有找到。

But I do this only when I'm not using the iOS Simulators in parallel, as the launchd_sim process is a child process of Simulator .但我只在不并行使用 iOS 模拟器时才这样做,因为launchd_sim进程是Simulator的子进程。

To speed up the build in Xcode Playground and prevent the loading icon to keep spinning forever:要加快 Xcode Playground 中的构建并防止加载图标永远旋转:

  1. go to the sidebar on the right, and change iOS to macOS in Playground Settings转到右侧的边栏,然后在Playground Settings中将iOS更改为macOS
  2. instead of importing UIKit , import Foundation而不是导入UIKit ,导入Foundation

(this would work if you're not trying to use specific stuff from tthe UIKit framework) (如果您不尝试使用UIKit框架中的特定内容,这将起作用)

I got this answer from: Ioannis Diamantidis - How to fix Xcode Playground getting stuck on "Running".我从 Ioannis Diamantidis - 如何修复 Xcode Playground 卡在“运行”中得到了这个答案。 I am using Xcode version 13.2.1 with a Mac Mini M1.我在 Mac Mini M1 上使用 Xcode 13.2.1 版。 I went to the playground icon on the top right corner - Hide or show the Inspectors, it says Playground Settings, I select in Platform macOs.我去了右上角的游乐场图标 - 隐藏或显示检查员,它说游乐场设置,我在 Platform macOs 中选择。 now my playground is running perfect, I see the results everywhere现在我的游乐场运行完美,我到处都能看到结果

我遇到了同样的问题,但在谷歌搜索和试验后,我发现在导入任何其他库之前必须始终import UIKit

Firstly, delete the inbuilt comment line.首先,删除内置的注释行。

Then, even if you put a first line comment back in, it still works.然后,即使您放回第一行注释,它仍然有效。 在此处输入图片说明

One last tip that works for me: Make sure no iOS simulator is running.对我有用的最后一个提示:确保没有 iOS 模拟器正在运行。 They conflict with each other.它们相互冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM