当我尝试编译 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/