```

... 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的更多相关文章

  1. 【104】Maven3.5.0结合eclipse使用,提示Lambda expressions are allowed only at source level 1.8 or above错误的解决方法

    错误重现 我的机器上安装了 maven 3.5.0,在 eclipse 中创建 maven 项目.pom.xml配置如下: <project xmlns="http://maven.a ...

  2. lambda expressions are not supported at this language level

    IDEA下报错:lambda expressions are not supported at this language level 解决: 1. File -> Project Struct ...

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

    我使用的是jdk1.8,使用lamb表达式的时候,报错 ambda expressions are not supported at this language level, 后来,设置了 接着重启了 ...

  4. AS报错:lambda expressions are not supported at this language level

    AS报错:lambda expressions are not supported at this language level 解决方法 打开打开 File --> Project Stuct ...

  5. swift错误和异常处理

    异常 (exception) 和错误 (error). 在 Objective-C 开发中,异常往往是由程序员的错误导致的 app 无法继续运行,比如我们向一个无法响应某个消息的NSObject 对象 ...

  6. 学习Swift -- 错误处理

    错误处理 错误处理是响应错误以及从错误中返回的过程.swift提供第一类错误支持,包括在运行时抛出,捕获,传送和控制可回收错误. 一些函数和方法不能总保证能够执行所有代码或产生有用的输出.可空类型用来 ...

  7. Swift 错误记录

    最近几天开始学习Swift,作为一个从 OC 转到 Swift 的程序员,我一直以为很简单.但是现在学习一个星期之后,发现问题还是蛮多的! 最大的问题就是 太特么 不习惯了!!!!!!!!!! 好吧, ...

  8. swift 错误集锦

    1.注册 NIB 出现错误 // error:'registerNib(_:forCellReuseIdentifier:)' has been renamed to 'register' (_:fo ...

  9. [Swift]错误提示:Method does not override any method from its superclass

    问题原因:方法名称书写错误! ViewController 生命周期 // 加载视图时会调用该方法 override func loadView() { super.loadView() print( ...

随机推荐

  1. 思维导图FreeMind安装问题及简单使用

    思维导图软件使用的坎坷之路 一直想将思维导图加入到工作环境当中 最开始使用的是 MindManager(http://www.mindmanager.cc/) ,而且感觉利用它制作出来的导图外观也比较 ...

  2. Zabbix监控mysql performance

    介绍 zabbix监控mysql性能,使用zabbix自带的mysql监控模板,可以监控以下内容OPS(增删改查).mysql慢查询数量.mysql请求\响应流量带宽 配置 新建mysql监控用户 G ...

  3. redis并发问题

    redis中的并发问题 使用redis作为缓存已经很久了,redis是以单进程的形式运行的,命令是一个接着一个执行的,一直以为不会存在并发的问题,直到今天看到相关的资料,才恍然大悟~~ 具体问题实例 ...

  4. js比较版本号

    比较版本v2.2.3和2.1.15大小 //假定字符串的每节数都在5位以下 function toNum(a){ var a=a.toString(); //也可以这样写 var c=a.split( ...

  5. 轮播插件unsilder 源码解析(一)---使用

    啰嗦几句:学习的可以直接省略,一直本着写原生的插件想法,但是前天看了吕大豹的博客觉得自己都没有正经的写个jquery插件:所以在开始写之前我会先对几个比较热门的jquery的插件进行源码分析:至于为什 ...

  6. iOS组件化思路 <转>

    随着应用需求逐步迭代,应用的代码体积将会越来越大,为了更好的管理应用工程,我们开始借助CocoaPods版本管理工具对原有应用工程进行拆分.但是仅仅完成代码拆分还不足以解决业务之间的代码耦合,为了更好 ...

  7. vim保存文件时,生成.un~文件

    在用vim保存文件时,文件夹下生成.un~文件 怎么删除这些文件呢 在网上搜索的答案: http://stackoverflow.com/questions/15660669/what-is-a-un ...

  8. (转)EasyUI-datagrid-自动合并单元格

    1.目标 1.1表格初始化完成后,已经自动合并好需要合并的行: 1.2当点击字段排序后,重新进行合并: 2.实现 2.1 引入插件 /** * author ____′↘夏悸 * create dat ...

  9. HDU 1859

    #include <iostream> #include <cstdio> #include <algorithm> #include <vector> ...

  10. [Machine Learning] logistic函数和softmax函数

    简单总结一下机器学习最常见的两个函数,一个是logistic函数,另一个是softmax函数,若有不足之处,希望大家可以帮忙指正.本文首先分别介绍logistic函数和softmax函数的定义和应用, ...