ios Xcode playground 卡在“正在运行的操场”或“启动模拟器”上并且无法运行代码,该怎么办?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39978092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 10:33:52  来源:igfitidea点击:

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

iosxcodexcode8

提问by Emil Osvald

Every time I create a new playground in order to test some code, Xcode gets stuck and won't run the code. 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. Sometimes this continues indefinitely and sometimes Xcode halts and prints this to console :

每次我创建一个新的 Playground 以测试一些代码时,Xcode 都会卡住并且无法运行代码。它只是在屏幕顶部显示“正在运行的操场”或“启动模拟器”语句,加载图标旁边有希望旋转,但没有任何反应。有时这会无限期地持续下去,有时 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)
2,5 GHz Intel Core i5
4 GB 1600 MHz Ram DDR3

硬件
MacBook Pro (13" Mid-2012)
2,5 GHz Intel Core i5
4 GB 1600 MHz Ram DDR3

I have looked around but at least neither of these threads have provided an answer:
https://forums.developer.apple.com/thread/5902
https://github.com/jas/playground/issues/9

我环顾四周,但至少这些线程都没有提供答案:
https: //forums.developer.apple.com/thread/5902
https://github.com/jas/playground/issues/9

Things I have already tried with zero success:

我已经尝试过零成功的事情:

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

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 让它几乎不可能......

Thank you in advance, cheers.

提前谢谢你,干杯。

回答by PANKAJ VERMA

Ans. Switch to macOS platform

答。切换到 macOS 平台

When you create a Playground, by default it select iOS platform and automatically imports UIKit. It's the UIKit which crashes and stuck all the time. If your (practice) code does not use UIKit then you can switch to MacOS platform. As major(not exact though) difference between iOS and macOS is in APPKit and UIKit.

创建 Playground 时,默认选择 iOS 平台并自动导入 UIKit。是 UIKit 一直崩溃和卡住。如果您的(练习)代码不使用 UIKit,那么您可以切换到 MacOS 平台。作为主要的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: enter image description here

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

回答by Aaeb

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. no space above import.
  3. press execute button
  1. 按下底部的“停止游乐场”按钮
  2. 删除第一个注释行并使 import 语句成为第一行。导入上方没有空格。
  3. 按执行按钮

回答by Khoa Vo

In my case, Xcode 8.3.2, it works when I try as steps below:

在我的情况下,Xcode 8.3.2,当我尝试以下步骤时它可以工作:

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

回答by dbv

Buggy Simulator's main process is still working even after Xcode closing. So here're the steps:

即使在 Xcode 关闭后,Buggy Simulator 的主进程仍在运行。所以这里是步骤:

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

回答by grain

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"
  2. Quit Xcode
  3. Restart Xcode
  1. 通过按住: ? Playground 左下角的箭头并选择“手动运行”
  2. 退出 Xcode
  3. 重启Xcode

It works very well.

它运作良好。

回答by Fiveagle

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 后尝试它

回答by SiBC

Adding import PlaygroundSupport solved the problem for me :)

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

回答by Sandhu

You can switch to manual processing. It worked for me. screenshot

您可以切换到手动处理。它对我有用。 截屏

回答by Asad Abbas

Make sure you kill xcode in the activity monitor before eventually killing com.apple.CoreSimulator.CoreSimulatorServiceprocess in the activity monitor. 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.CoreSimulatorServiceprocess would pop up again even when you just killed it.

在最终杀死活动监视器中的com.apple.CoreSimulator.CoreSimulatorService进程之前,请确保在活动监视器中杀死 xcode 。我多次尝试终止该进程,我意识到如果 xcode 仍在后台活动中运行,那么即使您刚刚杀死它,com.apple.CoreSimulator.CoreSimulatorService进程也会再次弹出。

回答by Farisk

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

我遇到了同样的问题,我所做的就是打开辅助编辑器,即使我关闭了辅助编辑器,一切正常!不要问为什么这是反复试验。希望能帮到你