Re: window of document

Andy Lee

It looks like there is no public getter for the "window" IBOutlet, even though Interface Builder knows about it and even though there is a public *setter*.

You can get to your window by way of the document's "windowControllers" array. Unless you've overridden makeWindowControllers to do otherwise, it will contain just one NSWindowController, and you can ask it for its window. This worked for me in a scratch app I just created.

If windowControllers does have multiple elements, I think you'll need to add some way to figure out which is the one you want. But I've never had that situation, so maybe there is a better answer.


On Mon, Feb 22, 2021, at 8:12 PM, James Walker wrote:
Say I create a new document-based Mac app in Xcode 12.4. In
Document.xib, I see that Document, the File’s Owner, has an outlet
“window”. But in the source code of the Document class, if I try to
refer to “self.window”, I get a compile error, “no getter method for
read from property”. I tried adding a property declaration for a
window IBOutlet property of Document, but then I got a weird situation
where the document creates an NSWindowController that does not own any
window. What’s going on? This is too basic, I’m sure that whatever
the answer is, it will make me slap my head and say “duh”.

Join { to automatically receive all group messages.