2

I am writing a simple application that loads into the status bar and when clicked it opens a popover under the status bar icon. I am using storyboards to define the UI I like to show in my popover. The thing is as soon as I instantiate the storyboard a window opens up. How can I prevent that? This is the code in my application delegate:

func applicationDidFinishLaunching(aNotification: NSNotification) {
    let mainBoard = NSStoryboard(name: "MainBoard", bundle: nil)
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
Farzad
  • 1,132
  • 9
  • 21
  • 1
    It is unclear what you are trying to achieve. - Every application must have a full-screen window. The line you have in your `applicationDidFinishLaunching` isn't doing anything. It is the association of storyboard with your app in Info.plist and the initial view in the storyboard that controls what appears – Paulw11 Apr 12 '15 at 01:55
  • My app loads an icon into the status bar. That's the app! When the icon is clicked a view is loaded and shown in a popover; therefore I don't need an initial window. – Farzad Apr 12 '15 at 02:11
  • change the iOS tag to OSX. It would be easier to achieve it if you deselect use storyboard when creating a new project. Then just deselect using the attributes inspector "visible at launch" – Leo Dabus Apr 12 '15 at 02:28
  • @Leonardo, do you mean xib files don't have this problem? – Farzad Apr 12 '15 at 02:32

1 Answers1

4
import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    var defaultWindow:NSWindow!
    func applicationDidFinishLaunching(aNotification: NSNotification) {
        defaultWindow = NSApplication.sharedApplication().windows.first as? NSWindow
        defaultWindow.close()

    }
    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }
    @IBAction func menuClick(sender: AnyObject) {
        defaultWindow.makeKeyAndOrderFront(nil)
    }
}

update: Xcode 7.1.1 • Swift 2.1

NSApplication.sharedApplication().windows.first?.close()
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571