swift错误 Expressions are not allowed at the top level

Posted 勇猛的小黑

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift错误 Expressions are not allowed at the top level相关的知识,希望对你有一定的参考价值。

```

... earlier we said top-level code isn’t allowed in most of your app’s source files. The exception is a special file named “main.swift”, which behaves much like a playground file, but is built with your app’s source code. The “main.swift” file can contain top-level code, and the order-dependent rules apply as well. In effect, the first line of code to run in “main.swift” is implicitly defined as the main entrypoint for the program. This allows the minimal Swift program to be a single line — as long as that line is in “main.swift”.

```

原因就是你把print等等表达式放到其他文件去了。在main.swift这个文件中写就没问题

知道怎么改就可以了。如果不满足的话,可以看看上面这段官方代码,写得真好



文/把时间当做朋友(简书作者)
原文链接:http://www.jianshu.com/p/6bc97afd9478
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

以上是关于swift错误 Expressions are not allowed at the top level的主要内容,如果未能解决你的问题,请参考以下文章

ElasticsearchES删除索引时报错“wildcard expressions or all indices are not allowed

关于idea中使用lamb表达式报错:ambda expressions are not supported at this language level

Swift:Errors thrown from here are not handled because the enclosing catch is not exhaustive

Swift:Errors thrown from here are not handled because the enclosing catch is not exhaustive

Timeexpressions是啥意思

错误:找不到模块“eslint/lib/rules/no-unused-expressions”