Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...