Title: How do I create an IBOutlet for NSWindow Xcode macOS
Tags: swift;macos;xcode9.2
Question: I am trying to create an IBOutlet for NSWindow in AppDelegate.swift, I am able to create IBOutlets for buttons by control + dragging from storyboard to swift file, but I am not able to do this for NSWindow. How do I do this?
Xcode 9.2 Swift 4.0
Thanks
Comment: `@property` is an ObjC keyword. You should be looking up how to use an @IBOutlet in Swift

Comment: Where is `@property` in that url link?

Comment: You can create an outlet for the controls available in the view library only.  Create a property if you want to reference the window in AppDelegate.

Comment: I tried using @property but it gives an error: ```unknown attribute 'property'```

Comment: I'm trying to do this https://stackoverflow.com/questions/34314789/osx-application-how-to-make-window-maximized

Here is the accepted answer: Create a window property:
weak var window: NSWindow?
Main window reference:
func applicationDidFinishLaunching(_ aNotification: Notification) {
window = NSApplication.shared.windows.first
Comment for this answer: @LeoDabus Thanks, that worked as well
Comment for this answer: @Dregg What you need is to use the view controller's view window property. Just make sure to access it on viewWillAppear or any other method other than viewDidLoad which window will always be nil https://stackoverflow.com/a/43426545/2303865
Comment for this answer: @Dregg Make sure to use the view window. It will always return the correct window. It is not necessarily always the first window.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:07/22/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<swift><macos><xcode9.2>', 'Title': 'How do I create an IBOutlet for NSWindow Xcode macOS', 'ViewCount': 107, 'id': 68487954, 'user_AboutMe': '', 'user_AccountId': 20383610.0, 'user_DisplayName': 'Dregg', 'user_Reputation': 593.0, 'user_Views': 620.0, 'user_id': 14953149.0}}