Quoc Dat Do Quoc Dat Do - 1 year ago 159
Swift Question

iOS - Type 'DispatchQueue' has no member 'GlobalAttributes'

enter image description hereI have this error

Type 'DispatchQueue' has no member 'GlobalAttributes'

`in this code. Do you know why?

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)

I also attached the file, just in case.

Answer Source

According to Apple's documentation, the message is correct.

Maybe you want to use DispatchQueue.Attributes?


I just had a closer look at the documentation:

DispatchQueue.global() seems to be changed. The documentation shows this declaration:

class func global(qos: DispatchQoS.QoSClass = default) -> DispatchQueue

I tested some variations, Xcode proposed and found this line:

let queue = DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated)

I did not test, if this works 100% with your example, but Xcode will compile it