Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change in Xcode 10 Playgrounds Variable Initialization change? Are Xcode 10 Playgrounds an interpreter?

I've noticed that Playgrounds in Xcode 10 no longer allow for the use of declared, but uninitialized variables. For example: while this code would work in an Xcode 9 playground, in an Xcode 10 playground (at least in Beta 1), it crashes:

var myValue: Int
//...
myValue = 100

print (myValue)

// Xcode 9 prints 100
// Xcode 10 reports an error: variables currently must have an initial value when entered at the top level of the REPL
  1. Is this the new behavior, or just a bug in the current Xcode 10 beta?

  2. I had been referring to earlier Xcode Playgrounds as an interpreter, but would one still consider Xcode 10 playgrounds to be an interpreter (and was that always correct)? Apple refers to the "Run" button in the gutter as "compiling" code.

Thanks!

like image 211
Gallaugher Avatar asked Dec 18 '22 22:12

Gallaugher


1 Answers

I hit this error. I had two different playgrounds up, one had the error and one did not. The issue was that "Automatically Run" was not set for my playground. To set the option, click on the play arrow at the top of the debug window in your playground and you will see the option to "Automatically Run", choose it.

Must be that Automatically Run mode is more like running an entire program, whereas manual run is not.

like image 51
Chris Avatar answered Apr 19 '23 23:04

Chris