English 中文(简体)
我如何确定多重探测器标签
原标题:How can I determine multiple finder (color) labels
  • 时间:2023-12-21 01:15:03
  •  标签:
  • swift
  • appkit

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
}

如果名录有不止一个彩色标签,则只有其中之一——最多。

问题回答

你正在获得不正确的资源价值。 如欲将颜色应用于档案,则需要tagNames资源。 该表以颜色名称及对档案适用的任何其他标记填入<代码>String阵列。

let rVals = try folder.resourceValues(forKeys: [.tagNamesKey])
if let tags = rVals.tagNames {
    print(tags)
} else {
    print("No tags")
}

tags will contain values such as "Red", "Green", etc. depending on the colors applied to the file. The colors are just tags.





相关问题
SwiftUI: How do I position a button x points above a sheet?

I am trying to recreate a Maps-style UI with a persistent bottom sheet and controls fixed above. Apple Maps UI with controls above ☝️ Example here, the "Look Around" binoculars button and ...

BraintreeDropIn deprecated functions error

I m getting this error on the latest release of BraintreeDropIn, I really don t get it since based on the patch notes, this should ve been addressed already, I have already tried cleaning derived data,...

how to limit zoom level in map swift ui?

how to limit zoom level in map swift ui i have map and need to make zoom level limited Map(coordinateRegion: $region,annotationItems: viewModel.nearbyGyms) { item in ...

UIImageView - How to get the file name of the image assigned?

Is it possible to read the name of an UIImageView s UIImage that s presently stored in the UIImageView? I was hoping you could do something kind of like this, but haven t figured it out. NSString *...

热门标签