Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
663 views
in Technique[技术] by (71.8m points)

read eval print loop - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...