0

I create a simple app for only status bar in macOS Swift.

I create a new NSWindowController and xib, when I call @objc function

self.aboutWindows.showWindow(self)

if I click it opens, but every time I click it opens a new window. How can I avoid it.

Same for another function of an NSMenuItem, I would like to start it only once.

Thanks

EDIT:

ALL IN APPDELEGATE

var aboutWindows = AboutWindows()

...

//TAP ON MENU ITEM
@objc func aboutWindows(_ sender: Any) {

    aboutWindows = AboutWindows(windowNibName: "AboutWindows")
    self.aboutWindows.showWindow(self)

}
nonickname
  • 181
  • 1
  • 3
  • 10
  • How, when and from where do you instantiate the window? – Willeke Feb 06 '20 at 14:46
  • @willeke When tap on “about” in app delegate by #selector(AppDelegate.aboutWindows()) (Because the app is only for status bar) – nonickname Feb 06 '20 at 18:40
  • I mean how, when and from where in your code do you instantiate the window? – Willeke Feb 09 '20 at 09:25
  • 1
    See [Avoid creation of multiple ViewController instances](https://stackoverflow.com/questions/46466660/avoid-creation-of-multiple-viewcontroller-instances-ios-swift) – Willeke Feb 15 '20 at 10:59

0 Answers0