You cannot demonstrate a progress bar in a loop like this.
, OS X , , . , 10, , , , - .
(progressbar.display()), , , , , 0,01 .
, incrementBy(1), . , - :
func delay(delay:Double, closure:()->()) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))),
dispatch_get_main_queue(), closure)
}
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var progressIndicator: NSProgressIndicator!
func applicationDidFinishLaunching(aNotification: NSNotification) {
let progressbar = NSProgressIndicator()
progressbar.frame = NSRect(x:100, y:20, width:150, height:10)
progressbar.minValue = 0
progressbar.maxValue = 10
self.window.contentView?.addSubview(progressbar)
self.progressIndicator = progressbar
progressIndicator.indeterminate = false
for i in 0...10 {
delay(1.0 * Double(i), closure: {
self.progressIndicator.incrementBy(1)
})
}
}
}
This queues the call incrementBy(1)at intervals of 1 second.
NSGod source
share