Xcode 10 Playgrounds 变量初始化的变化?Xcode 10 Playgrounds 是解释器吗? [英] Change in Xcode 10 Playgrounds Variable Initialization change? Are Xcode 10 Playgrounds an interpreter?

查看:35
本文介绍了Xcode 10 Playgrounds 变量初始化的变化?Xcode 10 Playgrounds 是解释器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到 Xcode 10 中的 Playgrounds 不再允许使用已声明但未初始化的变量.例如:虽然此代码可以在 Xcode 9 playground 中运行,但在 Xcode 10 playground(至少在 Beta 1 中),它会崩溃:

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. 这是新行为,还是当前 Xcode 10 beta 中的一个错误?

  1. Is this the new behavior, or just a bug in the current Xcode 10 beta?

我一直将早期的 Xcode Playgrounds 称为解释器,但人们还会将 Xcode 10 playground 视为解释器吗(而且总是正确的)?Apple 将装订线中的运行"按钮称为编译"代码.

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.

谢谢!

推荐答案

我遇到了这个错误.我有两个不同的操场,一个有错误,一个没有.问题是我的操场没有设置自动运行".要设置该选项,请单击 Playground 中调试窗口顶部的播放箭头,您将看到自动运行"选项,选择它.

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.

这篇关于Xcode 10 Playgrounds 变量初始化的变化?Xcode 10 Playgrounds 是解释器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆