cocoa - How to allow only one window in GUI in Swift -
i connected menu-object
window controller
. calling window controller
, i've added shortcut. on pressing shortcut multiple times, multiple windows opened. how call function, counts number of windows, , if it's 0
, it'll open window controller
, on pressing shortcut?
i'm using swift programming language.
you have static variable incremented on successful initialization of view , decrements on deinit of view. can check value in guard statement before initialization or set menu availability based on variable.
class windowcontroller: nswindowcontroller { static var count = 0 override func windowdidload() { windowcontroller.count += 1 } deinit { windowcontroller.count -= 1 } } func createwindow() { guard windowcontroller.count = 0 else { return } // create window here }
Comments
Post a Comment