This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func printHello(_ sender: Any) { | |
// 队列,以消息绑定为例 | |
if shouldWaitSwitch.isOn { | |
while true { | |
let isSuccess = WaitingTaskQueue.append(task: "你好!") | |
if isSuccess { break } else { continue } | |
} | |
if let _ = shouldWaitSwitch.actions(forTarget: WaitingTaskQueue.self, forControlEvent: .valueChanged) { // already set | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func printHello(_ sender: Any) { | |
// 消息绑定 | |
if shouldWaitSwitch.isOn { | |
if let _ = shouldWaitSwitch.actions(forTarget: self, forControlEvent: .valueChanged) { // already set | |
return | |
} | |
shouldWaitSwitch.addTarget(self, action: #selector(printHello(_:)), for: .valueChanged) | |
} | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func printHello(_ sender: Any) { | |
// 延迟 | |
if shouldWaitSwitch.isOn { | |
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: { [unowned self] (timer) in | |
if self.shouldWaitSwitch.isOn { return } | |
print("你好!") | |
timer.invalidate() | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func printHello(_ sender: Any) { | |
// 忙等待 | |
DispatchQueue(label: "default").async { | |
while true { | |
if self.shouldWaitSwitch.isOn { continue } | |
print("你好!") | |
break | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rawFilenames = [String]() | |
// instance counter | |
var timer:NSTimer! = nil | |
func application(sender: NSApplication, openFiles filenames: [String]) { | |
if shouldQuitAppAfterConvert == nil { | |
shouldQuitAppAfterConvert = true | |
} | |
if timer != nil { | |
timer.invalidate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TableViewController: NSViewController, NSTableViewDelegate { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do view setup here. | |
run() | |
DispatchQueue.main.asyncAfter(wallDeadline: .now() + .milliseconds(100)) { [unowned self] () -> () in | |
NotificationCenter.default.post(name: TableViewControllerDidAppear, object: self) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TableViewController: NSViewController, NSTableViewDelegate { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do view setup here. | |
run() | |
Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(sendNotification), userInfo: nil, repeats: false) | |
} | |
func sendNotification() { | |
NotificationCenter.default.post(name: TableViewControllerDidAppear, object: self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in AppDelegate.swift | |
let TableViewControllerDidAppear = NSNotification.Name("TableViewController did Appear") | |
// in PreferencesViewController.swift | |
class PreferencesViewController: NSViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do view setup here. | |
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange), name: UserDefaults.didChangeNotification, object: UserDefaults.standard) | |
NotificationCenter.default.addObserver(self, selector: #selector(tableViewDidAppear(noti:)), name: TableViewControllerDidAppear, object: nil) |
NewerOlder