Skip to content

Instantly share code, notes, and snippets.

@owenzhao
Created November 1, 2016 14:54
Show Gist options
  • Save owenzhao/9a5247709072376f68cf67af9e013d2d to your computer and use it in GitHub Desktop.
Save owenzhao/9a5247709072376f68cf67af9e013d2d to your computer and use it in GitHub Desktop.
stop main runloop to change the running order of progress indicator
func userDefaultsDidChange() {
guard let controller = tableViewController else { return }
let progressIndicator = { () -> NSProgressIndicator in
let frame = view.frame
let x = (frame.width - 50) / 2
let y = (frame.height - 50) / 2
let piFrame = NSMakeRect(x, y, 50, 50)
let pi = NSProgressIndicator(frame: piFrame)
pi.style = .spinningStyle
return pi
}()
view.addSubview(progressIndicator)
progressIndicator.startAnimation(self)
RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.001))
controller.run()
progressIndicator.stopAnimation(self)
progressIndicator.removeFromSuperview()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment