我有以下错误:
类型'DispatchQueue'没有成员'GlobalAttributes'
在我的代码中。你知道为什么吗?
public typealias Classification = (Label: DigitLabel, Confidence: CGFloat, BestPrototypeIndex: Int)
public func classifyDigit(digit: DigitStrokes, votesCounted: Int = 5, scoreCutoff: CGFloat = 0.8) -> Classification? {
if let normalizedDigit = normalizeDigit(inputDigit: digit) {
let serviceGroup = DispatchGroup()
let queue = ***DispatchQueue.global(attributes: DispatchQueue.GlobalAttributes.qosUserInitiated)***
let serialResultsQueue = DispatchQueue(label: "collect_results")
var bestMatches = SortedMinArray<CGFloat, (DigitLabel, Int)>(capacity: votesCounted)
for (label, prototypes) in self.normalizedPrototypeLibrary {
queue.async(group: serviceGroup) {
var localBestMatches = SortedMinArray<CGFloat, (DigitLabel, Int)>(capacity: votesCounted)
var index = 0
for prototype in prototypes {
if prototype.count == digit.count {
let score = self.classificationScore(sample: normalizedDigit, prototype: prototype)
//if score < scoreCutoff {
localBestMatches.add(value: score, element: (label, index))
//}
}
index += 1
}
serialResultsQueue.async(group: serviceGroup) {
for (score, bestMatch) in localBestMatches {
bestMatches.add(value: score, element: bestMatch)
}
}
}
}
我还附上the file,以防万一。
答案 0 :(得分:1)
根据Apple's documentation,消息是正确的。
也许你想使用DispatchQueue.Attributes
?
修改强>
我只是仔细看了一下文档:
DispatchQueue.global()
似乎有所改变。文档显示了这个声明:
class func global(qos: DispatchQoS.QoSClass = default) -> DispatchQueue
我测试了一些变体,Xcode提出并找到了这一行:
let queue = DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated)
我没有测试,如果这对你的例子100%有用,但Xcode会编译它