Для macOS. В NSViewController eсть @IBAction и в нем есть несколько OperationQueue(). В каждой есть свой childProgress. Как организовать parentProgress для индикатора выполнения метода?
let myArray1 = ["string1", "string2" ... ]
let myArray2 = ["string1", "string2" ... ]
let queue1 = OperationQueue()
let queue2 = OperationQueue()
let childProgress1 = Progress()
let childProgress2 = Progress()
let parentProgress = Progress()
parentProgress.totalUnitCount = 10
private var progressObservationContext = 0
let blockOperation1 = BlockOperation
{
childProgress1.totalUnitCount = Int64(myArray1.count)
for each in myArray1
{
... //something 1
childProgress1.completedUnitCount += 1
}
}
queue1.addOperation(blockOperation1)
let blockOperation2 = BlockOperation
{
childProgress2.totalUnitCount = Int64(myArray2.count)
for each in myArray2
{
... //something 2
childProgress2.completedUnitCount += 1
}
}
queue2.addOperation(blockOperation2)
где то надо прописать. Где ?
let options : NSKeyValueObservingOptions = [.new, .old, .initial, .prior]
parentProgress.addObserver(self, forKeyPath: "localizedDescription", options: options, context: &progressObservationContext)
parentProgress.addChild(childProgress1, withPendingUnitCount: 5)
parentProgress.addChild(childProgress2, withPendingUnitCount: 5)
....
parentProgress.removeObserver(self, forKeyPath: "localizedDescription")