8

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

6
  • You can stop Xcode from crashing and make it behave as expected by submitting a bug report at bugreport.apple.com Commented Apr 5, 2017 at 23:20
  • @Pallie - It has been reported ffor over a year is Apple Discussion groups together with a bug rejected as a duplicate. How are people working around this known bug? Commented Apr 10, 2017 at 15:01
  • Well you can work around by analyzing the error message, which exactly states what is wrong and at which line the issue occurred. You can enable line numbers in the preferences of Xcode (Text Editing>Editing>Show line numbers). Commented Apr 10, 2017 at 15:59
  • 1
    So is this what everyone else does? Commented Apr 10, 2017 at 16:45
  • 1
    @Mark no this is why I hardly ever use Playgrounds. They're cute, but when you try to get anything complex to work they hardly work. Errors are too hard to diagnose. That may change with Xcode 9 beta 6 (from my testing), which appears to trim all that garbage stack frame output, and it is currently inlining the error/suggestion/fix. Commented Aug 30, 2017 at 16:25

6 Answers 6

22

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.

enter image description here

I had the same problem as you (red marks wasn't showing up on the left). What solved for me:

  1. Right click the error on Issue Navigator (top left panel)
  2. On the Menu > Open As > Quick Look
  3. Then do the same command again and Open As > Playground Page

I'm on Xcode 8.3.2

Update: Same is valid for Xcode 9.0

Sign up to request clarification or add additional context in comments.

4 Comments

Not for me IT DOES NOT SHOW THIS. well most of the time. Some times on the first error or two in a session it shows the red icon then text is never thgere unless you click on a few things. As noted it is a known Apple bug.
Thank you. The number of weird issues in Xcode that have fixes like this is a little concerning.
Hey guess who's back... What worked for me is, make another, more "obvious" error (!), and hopefully it triggers the red mark - which happened to work now. Man is this how everyone makes iOS Apps? I feel so bad...
Xcode 10.1 and still the same issue. Errors showing for some time and then bang, can't navigate through errors.
9

In the issue navigator, right click the error -> open as quick look, then select it back to open as playground. It works for me.

1 Comment

To restate, in the Issue Navigator / Buildtime, context menu: Open As -> Quick Look, then Open As -> Playground should force a workaround to refresh the display of the errors being marked at the line numbers.
2

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 Show example of it working

Settings are Settings needed

Comments

1

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: enter image description here

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

2 Comments

Oh, yeah, but let's see you make it look that way at my house! :)
I'm going to have a terribly hard time doing that, since Playgrounds are so buggy. I need to submit more bug reports ... close and open Xcode, start a new Playground... try something different?
0

Deleting Derived Data and quitting Xcode worked for me.

Comments

-2

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:

enter image description here

This is what you see an app project:

enter image description here

7 Comments

So effectively playgrounds are useless when you have an error?
In Apple's WWDC video at 20:40 he shows a red mark on left hand side and clicking gives the error. I get no red at all
Xcode 9 Beta 6 seems to fix this problem. I've never used Playgrounds much because the errors are so hard to find, and in Xcode 8.3.3 it doesn't show inline as far as I can tell. That may be a bug, but I've always found Playgrounds frustrating to do any serious work. Making a macOS terminal app or an iPhone app seems the way to go, macOS terminal will give you something that feels just like a playground, except it'll provide all the error inline help you expect in Xcode 8.3.3.
@PaulSolt I'm using Xcode 9 Beta 6 and I don't see how it "fixes this problem". It's just like my screen shot of a playground, not like my screen shot of an app. No issue markers appear inline in the source code, regardless of settings etc.
@matt actually, this is super buggy still in Xcode 9 beta 6. Sometimes it works, but other times it seems like compiler chokes and stops providing useful feedback. Closing Xcode and reopening seemed to get it working again (temporarily)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.