我正在尝试使用Swift 包管理器创建一个示例,在其中创建一个小型库,将其托管在我的 github 上,然后使用该库作为依赖项来创建可执行的Swift 程序。
这是我的设置:
图书馆
MyXMLHelper.swiftclass MyXMLHelper {
static func enclose(text: String, withXMLTag tag: String) -> String {
let openingTag = "<\(tag)>"
let closingTag = "</\(tag)>"
return openingTag + text + closingTag
}
}
包.swift
import PackageDescription
let package = Package(
name: "XMLHelper"
)
也欢迎您在我的github上查看原始版本。
可执行文件(命令行)
main.swiftimport XMLHelper
print("Please enter a text you would like to enclose: ", terminator: "")
let text = readLine()!
print("Please enter the XML tag: ", terminator: "")
let tag = readLine()!
let result = MyXMLHelper.enclose(text: text, withXMLTag: tag)
print("Result: \(result)")
包.swift
import PackageDescription
let package = Package(
name: "XML_application",
dependencies: [
.Package(url: "https://github.com/nikolasburk/xml-util",
majorVersion: 2),
]
)
运行后swift build
,文件夹结构如下:
因此,swift build
成功下载了依赖项,但它也给了我以下错误:
/Users/nburk/Projects/makeschool/tutorials/swift-package-manager-demo/xml-app/main.swift:9:14: error: use of unresolved identifier 'MyXMLHelper'
let result = MyXMLHelper.enclose(text: text, withXMLTag: tag)
^~~~~~~~~~~
<unknown>:0: error: build had 1 command failures
error: exit(1): /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-08-24-a.xctoolchain/usr/bin/swift-build-tool -f /Users/nburk/Projects/makeschool/tutorials/swift-package-manager-demo/xml-app/.build/debug.yaml
有谁知道这是为什么?为什么找不到类MyXMLHelper
,它不应该在这里可见吗?