在 Linux 上的项目 Swift 中声明的模块

Modules declared in files Swift project on Linux

我正尝试在 Fedora 30.0 上开始一个新的 Swift 项目用于一些培训目的。该项目由 2 个简单文件组成:

main.swift

let req: Request = RequestImpl()
req.sendRequest(url: "hello")

Request.swift

protocol Request {
    func sendRequest(url: String)
}

final class RequestImpl: Request {

    // MARK: - Request

    func sendRequest(url: String) {
        print(url)
    }
}

问题

当我在终端上运行命令swiftc main.swift时,出现以下错误:

$ swiftc main.swift 
main.swift:1:10: error: use of undeclared type 'Request'
let req: Request = RequestImpl()
         ^~~~~~~

P.S: I 运行 swiftc Request.swift 在 运行 上面的命令之前。

这应该可以编译,但打印不起作用:

$ swiftc Request.swift main.swift

如果你想创建包含多个文件的模块并且运行它,我会建议create executable package, build and run it