gpt4 book ai didi

ios - 运行后 `swift build` dependencies are downloaded by class is not found

转载 作者:行者123 更新时间:2023-11-28 06:35:43 25 4
gpt4 key购买 nike

我正在尝试使用 Swift Package Manager 创建一个示例,我正在创建一个小型,将其托管在我的 github 上,然后将此库用作依赖项创建一个可执行 Swift 程序。

这是我的设置:

图书馆

enter image description here

MyXMLHelper.swift
class MyXMLHelper {

static func enclose(text: String, withXMLTag tag: String) -> String {
let openingTag = "<\(tag)>"
let closingTag = "</\(tag)>"
return openingTag + text + closingTag
}

}
Package.swift
import PackageDescription

let package = Package(
name: "XMLHelper"
)

也欢迎您在我的github上查看原始版本.

可执行文件(命令行)

ma​​in.swift
import 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)")
Package.swift
import PackageDescription

let package = Package(
name: "XML_application",
dependencies: [
.Package(url: "https://github.com/nikolasburk/xml-util",
majorVersion: 2),
]
)

运行 swift build 后,文件夹结构如下所示:

enter image description here

所以,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,它不应该在这里可见吗?

最佳答案

这可能是因为您的类(class)不是公开的。

MyXMLHelper.swift 中,应该这样声明:

public class MyXMLHelper {

或者,如果您希望能够对其进行子类化(Xcode 8 beta 6):

open class MyXMLHelper {

关于ios - 运行后 `swift build` dependencies are downloaded by class is not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39148376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com