Monday, August 4, 2014

Unable to Decode Playground Data

I've been coding in Xcode's Playground using Swift for the past two months. It seemed that my code was touching on an Xcode edge case causing it to stop evaluating with an error message: "Error running playground. Unable to decode playground data." I can tell where the problem is since the playground sidebar stops displaying output at the line of code that's choking. But I can't tell what the problem is.

The line of code having the problem is a function call at the end of a do..while loop. I initially thought my string manipulation was causing the issue since Swift strings are a little different than the Java NSString that I'm used to in WebObjects.

Narrating One's Work

I figured it might help if I wrote about my issue. Perhaps someone else is having the same problem. A quick Google search shows that a few people are encountering the same issue. But too few are having this problem to find a definitive solution other than chalking it up to an ongoing Xcode bug.

Almost There

I initially thought I had discovered the cause, earlier today, when I changed the half-open range operator to a closed range operator (i.e. I changed ...  to ..<). Once I made that change my playground compiled all the way to the end. But this was a short-lived victory when I restarted Xcode and the playground error returned. Toggling between the half-open and closed range operators at least gets my code to compile and run in the playground. So, perhaps I'm getting closer.


Matt Gibson said...

I can't reproduce this, I'm afraid. Do you have some test data or a little more code that always does this? Are you using the latest beta, beta 5?

(Also, I'd note that your function is allocating a new Array the length of the string every time you loop it. Personally, I'd probably use a "for ch in newString" loop to iterate the Characters of the string, and manually increment a counter.)

Joe Moreno said...

Good advice about not creating a new array each loop iteration. It seems to be working, now, more reliably after fiddling with the ... and the ..<. Puzzling.

Evghenii Nicolaev said...

func doSomething() -> String {
return "Somethindg!"


I got same error in this simple function, and it's because of an whitespace character.
Try to see where it stops to execute and then delete all white spaces. I cannot find another reason

gregt said...

I was getting this error in my playground and made it go away with these steps:
cut the code from the playground editor to the clipboard, then save the playground file (empty), and then paste the code back in to the playground. YMMV

Unknown said...

Similar to gregt i was copying the text from a book (usually type to make my fingers learn the patterns) but this was really simple tuples for data and it was just a spurious character. Copied to sublime text and back.