Reputation: 32626
I am beginning Swift and using tutorials in Swift playgrounds for macOS.
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
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 Version 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
Upvotes: 7
Views: 7332
Reputation: 3489
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.
I had the same problem as you (red marks wasn't showing up on the left). What solved for me:
I'm on Xcode 8.3.2
Update: Same is valid for Xcode 9.0
Upvotes: 22
Reputation: 8395
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.
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.
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.
... 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
Upvotes: 1
Reputation: 421
In the issue navigator, right click the error -> open as quick look, then select it back to open as playground. It works for me.
Upvotes: 9
Reputation: 1905
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.
Edit: In fact, I just opened a playground I created pre-patch, and errors show inline
Upvotes: 2
Reputation: 534885
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 would get 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.)
So, this is what you see in a playground:
This is what you see an app project:
Upvotes: -2