Подходящим решением является KVO
. Прежде чем цикл добавит наблюдателя (предполагается, что queue
является экземпляром OperationQueue
)
queue.addObserver(self, forKeyPath:"operations", options:.new, context:nil)
Затем реализуем
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if object as? OperationQueue == queue && keyPath == "operations" {
if queue.operations.isEmpty {
// Do something here when your queue has completed
self.queue.removeObserver(self, forKeyPath:"operations")
}
} else {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
}
}
Изменить:
В Swift 4 намного проще
Объявить свойство:
var observation : NSKeyValueObservation?
и создать наблюдателя
observation = queue.observe(\.operationCount, options: [.new]) { [unowned self] (queue, change) in
if change.newValue! == 0 {
// Do something here when your queue has completed
self.observation = nil
}
}
с использованием пакета directlabels и собирающего раствора из этого
# Basic plot
v <- ggplot(volcano3d, aes(x, y, z = z))
library(directlabels)
v2 <- v + stat_contour(aes(colour = ..level..))
direct.label(v2, method="bottom.pieces")
[/g1]
method="bottom.pieces"
(илиtop.pieces
) к вызовуdirect.label
– jaimedash 19 May 2016 в 01:04