swift - 从swift设置查找器标签?

标签 swift macos

我可以使用以下代码在 swift 中获取 finder 标签:

if let tagArray = try url.resourceValues(forKeys:[.tagNamesKey]).tagNames {
    ...
}

但是设置会报错:

var values = URLResourceValues()
values.tagNames = finderTags

给出错误:

Compile Swift Module 'tagsync' (1 sources)
main.swift:104:20: error: cannot assign to property: 'tagNames' is a get-only property
                    values.tagNames = finderTags
                    ~~~~~~~~~~~~~~~ ^

如何在 swift 中编写标签?

最佳答案

您可以使用 NSURL(而非 URL)轻松编写 Finder 标签:

let myPath = "any POSIX path; spaces ok"  
var myFinderTags = ["a", "b", "c"]  
try NSURL(fileURLWithPath: myPath).setResourceValues([.tagNamesKey: myFinderTags])

关于swift - 从swift设置查找器标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47464898/

相关文章:

delegates - Swift 使用用 Objective-C 编写的委托(delegate)

macos - gcc 不工作 - Xcode 3.2.6 - 雪豹

git - 通过SSH连接vscode到gitlab的问题

swift - 如何获取 UITableView 中的所有 UITextField 值?

macos - 如何从NSImage保存PNG文件(视网膜问题)

macos - 由于环境错误 : [Errno 13] Pip install Pytest,无法安装软件包

swift - Metal 内核在新款 MacBook Pro(2016 年末)GPU 上无法正常运行

swift - 原生swift zip解压

swift - 属性初始值设定项在 'self' 可用之前运行

swift 3 - 搜索结果也带有变音符号