首页 > 代码库 > swift错误 Expressions are not allowed at the top level
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
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
原文链接:http://www.jianshu.com/p/6bc97afd9478
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
swift错误 Expressions are not allowed at the top level
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。