Normally I would use this method to open a new window using a window controller
@class WindowTestController; @interface AppDelegate : NSObject <NSApplicationDelegate> { IBOutlet NSWindow *window; WindowTestController *windowController; } @property (weak) IBOutlet NSWindow *window; @property (strong) WindowTestController *windowController; - (IBAction) buttonClicked:(id)sender; @end
And then
When trying to do this in swift, I have the following
import Cocoa class AppDelegate: NSObject, NSApplicationDelegate { var testWindow: NSWindowController = WindowTestController(windowNibName: "Window") @IBOutlet var window: NSWindow @IBAction func buttonClicked(sender : AnyObject) { testWindow.showWindow(nil) } func applicationDidFinishLaunching(aNotification: NSNotification?) {
In this situation, since I have to set the default value for the testWindow property, I create an instance of WindowTestController before I need it. that is, I do not need to do
if (windowController == nil)
Is this correct or is there another method that allocates the resource when it is required, or am I not worried about anything?
Performance
if (windowController == nil) testWindow = WindowTestController(windowNibName: "Window") }
Without the AppDelegate property. The results in the window disappear immediately (e.g. deallocated, I think).
source share