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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -