I am trying to determine all of the color labels on a directory. When I check the URLResourceValues of a directory URL it only seems to return the "top" or most recent one, however a directory can have more than one label.
The URL extension Code I m using to re thebell from a URL:
extension URL {
func hasFinderLabel() -> ColorLabel {
let folder = self
var rVals = URLResourceValues()
do {
rVals = try folder.resourceValues(forKeys: [.labelNumberKey, .labelColorKey])
} catch {}
if let colorLabels = rVals.labelColor {
print(colorLabels)
}
let colorNumber : Int = rVals.labelNumber ?? 0
var colorLabel : ColorLabel
switch colorNumber {
case 0:
colorLabel = .none
case 1:
colorLabel = .gray
case 2:
colorLabel = .green
case 3:
colorLabel = .purple
case 4:
colorLabel = .blue
case 5:
colorLabel = .yellow
case 6:
colorLabel = .red
case 7:
colorLabel = .orange
default:
colorLabel = .none
}
return colorLabel
}
}
enum ColorLabel : Int {
case none
case gray
case green
case purple
case blue
case yellow
case red
case orange
}
如果名录有不止一个彩色标签,则只有其中之一——最多。