我可以使用以下代码在 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/