Hi, caught in a loop of unhelpful error messages. Been trying to find a code example to follow, apparently that is not a thing anymore. the docs... for over 20 years now are only half finished. So Im here in the forums looking for guidance.
I am trying to set a resource for an existing file URL. the intention is to add a tag to the file. Nothing onerous. Should be easy. Getting the list of tags WAS easy.
here's the code as I have it:
func setItemTags(atURL:URL, tags: [String]){
do {
try atURL.setResourceValue(tags, forKey: .tagNamesKey)
} catch let error as NSError {
print(error)
}
}
I get an error that says: Argument type '[String]' expected to be an instance of a class or class-constrained type
ok. seems pretty straight forward, the Array (which is what I get from acquiring the resources... so this doesn't make much sense at all, but whatever.) needs to be a class. clearly it's a Holdover from Obj-c. And it needs to be an NSArray. I SHOULD be able to bridge to an NSArray by replacing 'tags' with 'NSArray(array: tags)'
but that doesn't work at all. I get a different error. 'setResourceValue(:forKey:)' is unavailable: Use struct URLResourceValues and URL.setResourceValues(:) instead
So no error message is really telling us anything. no matter how much I try, I can't just materialize the answer out of thin air.
what I really need is a single example of how to properly use the 'steresourceValue' function of URL, to set the .tagNamesKey. I am astonished that this is not documented anywhere.*
*I have found ancient examples of this, which is now deprecated by changes to swift, and is only useful as a source of confusion.