swift - Ubuntu 14.04 中出现 "swift build"错误

标签 swift ubuntu ubuntu-14.04 nsregularexpression

当我尝试编译 Swift 代码时遇到问题,我相信它与 Ubuntu 中的 Swift 有关。这是错误:

swift build 

Compiling Swift Module 'testregex' (1 sources) /home/guillermo/Descargas/Hola/Sources/testregex.swift:4:1: error: statements are not allowed at the top level if let range = str.rangeOfString("string$", options: .RegularExpressionSearch) { ^ <unknown>:0: error: build had 1 command failures

error: exit(1): ["/home/guillermo/Descargas/swift-DEVELOPMENT-SNAPSHOT-2016-01-25-a-ubuntu14.04/usr/bin/swift-build-tool", "-f", "/home/guillermo/Descargas/Hola/.build/debug/testregex.o/llbuild.yaml"]

如果有人知道如何解决这个奇怪的问题,我将非常感激 :)

最佳答案

这是因为 swift build 期望在 Sources 文件夹中找到一个 main.swift 文件。

将您的 testregex.swift 文件重命名为 main.swift 它将正确构建。

您可以在 Sources 文件夹中拥有任意多个 .swift 文件,但必须有一个 main.swift 文件。

关于swift - Ubuntu 14.04 中出现 "swift build"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35834751/

相关文章:

ios - 如何使用 UIScrollView 显示下一个 View 的边缘

swift - 删除按钮未出现在 UITableViewCell 中

c++ - 我在 Qt 设计器文件->新建中找不到 C++ 项目

ubuntu - 进程 plymouth-upstart-bridge 不断终止

objective-c - Swift 中的完成 block 语法

ubuntu - Docker构建错误/bin/sh : 1: apt-get: not found

ubuntu - cmake 为 root 工作而不为其他用户工作

Java + PDFBox 无法在 Linux 服务器上运行

mysql - 如何解决 ubuntu 14.04 安装 mysql-server 时未满足的依赖关系

swift - 将 Firebase Auth 用户 UID 写入数据库