Decision:
1 - The first argument to setResourceValue must be NSArray
2 - Shocking, but ... the color name must be localized!
In this example, error 8050 is fixed, but the color mark is not actually set if your system language is not English:
var error: NSError? let theURL:NSURL = NSURL(fileURLWithPath: "/Users/me/tests/z.png")! let tag: AnyObject = NSWorkspace.sharedWorkspace().fileLabels[4] // "Blue" tag let arr = NSArray(object: tag) theURL.setResourceValue(arr, forKey: NSURLTagNamesKey, error: &error)
On my system (French), this does not set the actual label of the blue label, but only a text tag containing the word "blue".
To set the correct color tag, you must specify the localized color name literally:
var error: NSError? let theURL:NSURL = NSURL(fileURLWithPath: "/Users/me/tests/z.png")! let arr = NSArray(object: "Bleu")
source share