swift - 如何将数据文件与 macOS 终端应用程序捆绑在一起?
问题描述
我正在尝试将文本文件与我正在构建的 macOS 命令行工具捆绑在一起。我已将文件添加到项目中,但似乎无法从代码中访问它。我的项目如下所示:
我用来尝试加载数据的函数如下所示:
func loadFile() -> [String] {
let fileName = "small_names"
guard let url = Bundle.main.url(forResource: fileName, withExtension: "txt") else {
print("couldn't open \(fileName)")
return []
}
// load that URL
}
然而,url
似乎总是nil
。当我运行程序时,我会couldn't open small_names
打印出来。
我需要做什么才能将这个文件与我的程序一起发送?如何从代码中获取其 url?
谢谢。
解决方案
推荐阅读
- python - 比较 2 个 ID 列上的 2 个 CSV 并将匹配项写入新的 csv
- networking - Ansible playbook 从交换机内部远程登录交换机以更新静态路由
- android - 如何从 recyclerview 适配器中删除项目
- powershell - 如何使用 PowerShell 过滤 CSV 文件?
- video - 检测 h264 访问单元可能的位置
- python - 访问烧瓶中POST方法发送的由换行分隔的数据
- reactjs - Reactjs Typescript联系参数问题
- javascript - .NET Core 如何在运行时验证 JS 代码
- java - JUnit 测试错误:java.lang.NoClassDefFoundError:org/junit/platform/commons/PreconditionViolationException
- reactjs - 反应本机 USSD 链接