xcode Swift Playground 没有显示错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43241749/
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
Swift Playground not showing errors
提问by user151019
I am beginning Swift and using tutorials in Swift playgrounds for macOS.
我正在开始使用 Swift 并在 macOS 的 Swift 游乐场中使用教程。
So example code would be
所以示例代码是
var str = "Hello, playground"
str
str1
I do not get any red error information on the str 1. Just a crash in the console
我在 str 1 上没有收到任何红色错误信息。只是控制台崩溃了
Playground execution failed: error: MyPlayground.playground:1:1:
error: use of unresolved identifier 'str1'
str1
^~~~
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x0000000102157360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground
frame #1: 0x000000010215522a com.apple.dt.Xcode.PlaygroundStub-macosx`-[PlaygroundViewBridgeService execute] + 90
If I correct the code then the playground does refresh and show new data it is just not reporting the errors
如果我更正代码,那么操场会刷新并显示新数据,它只是不报告错误
How do I stop Xcode from crashing and behave as documented?
如何阻止 Xcode 崩溃并按照文档进行操作?
Xcode Version 8.3 (8E162) macOS 10.12.4
Xcode 版本 8.3 (8E162) macOS 10.12.4
I've tried deleting all Xcode files (including the ones that it creates during a build) and reinstalling and using a different user
我已经尝试删除所有 Xcode 文件(包括它在构建过程中创建的文件)并重新安装和使用不同的用户
采纳答案by matt
What you're seeing is correct behavior. If you want the "red marks" inline with your code, use a real project. Playgrounds don't show all errors, and if they do show them, they show them as you described, in console, first with the same message you wouldget in the "red marks" and then with the rather pointless crash log. (It is not Xcode that is crashing; it's the special playground execution process.)
你所看到的是正确的行为。如果您希望代码内嵌“红色标记”,请使用真实项目。像你描述的,在控制台上,先用同样的消息,你的操场不显示所有的错误,如果他们这样做给他们,他们表现出他们将获得在“红印”,然后用相当没有意义的崩溃日志。(崩溃的不是 Xcode;而是特殊的操场执行过程。)
So, this is what you see in a playground:
所以,这就是你在操场上看到的:
This is what you see an app project:
这是你看到的一个应用项目:
回答by Marcos Reboucas
Actually a Playground does show the "red mark error on the left side of code"and there's also an automatic option to fix the error, just as regular Projects.
实际上,Playground 确实会显示“代码左侧的红色标记错误”,并且还有一个自动选项来修复错误,就像常规项目一样。
I had the same problem as you (red marks wasn't showing up on the left). What solved for me:
我和你有同样的问题(左边没有出现红色标记)。为我解决了什么:
- Right click the error on Issue Navigator (top left panel)
- On the Menu > Open As > Quick Look
- Then do the same command again and Open As > Playground Page
- 右键单击问题导航器上的错误(左上面板)
- 在菜单 > 打开为 > 快速查看
- 然后再次执行相同的命令并打开为 > 游乐场页面
I'm on Xcode 8.3.2
我在 Xcode 8.3.2
Update: Same is valid for Xcode 9.0
更新:同样适用于 Xcode 9.0
回答by SuperBatman
In the issue navigator, right click the error -> open as quick look, then select it back to open as playground. It works for me.
在问题导航器中,右键单击错误 -> 以快速查看的方式打开,然后将其选回以作为操场打开。这个对我有用。
回答by froggomad
File -> Playground Settings
check show live issues for source code
select show all issues radial button
文件 -> 操场设置
检查显示源代码的实时问题
选择显示所有问题单选按钮
Xcode was, in fact, as of 3/2017 showing errors inline in the playground, just as it does in a project when editing a file. This behavior changed in a recent update, though I don't see it documented. I assumed it was a bug introduced with the latest patch, or perhaps a default setting was changed that can be changed back.
事实上,截至 2017 年 3 月,Xcode 会在操场上显示内联错误,就像在项目中编辑文件时一样。这种行为在最近的更新中发生了变化,但我没有看到它被记录在案。我认为这是最新补丁引入的错误,或者可能更改了默认设置,可以改回来。
Edit: In fact, I just opened a playground I created pre-patch, and errors show inline
回答by Paul Solt
Sometimes this feature works, more often than not, it doesn't. Xcode 8.3.3 has been very buggy with this feature, and made me avoid using Playgrounds.
有时此功能有效,但通常无效。Xcode 8.3.3 在这个功能上有很多问题,让我避免使用 Playgrounds。
Here's a screen when it works in Xcode 9 Beta 6:
Quitting and re-opening Xcode seems to help make it work again, but the tools seem to get confused pretty easily as I'm experimenting with code.
退出并重新打开 Xcode 似乎有助于使其再次工作,但在我试验代码时,这些工具似乎很容易混淆。
When I mess up the code, that causes issues, Playgrounds will stop trying to recompile, then I get a stale feedback loop, and have no idea if the code is working or not.
当我弄乱代码时,会导致问题,Playgrounds 将停止尝试重新编译,然后我得到一个陈旧的反馈循环,并且不知道代码是否有效。
... moments after I had a Playground working in Xcode 9 Beta 6 it stopped working. Errors stopped displaying inline, so I'd recommend filing more bug reports at http://bugreport.apple.com
...在我在 Xcode 9 Beta 6 中使用 Playground 后不久,它就停止工作了。错误停止内联显示,因此我建议在http://bugreport.apple.com 上提交更多错误报告
回答by guptron
Deleting Derived Data and quitting Xcode worked for me.
删除派生数据并退出 Xcode 对我有用。