<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 12 Apr 2026 03:20:08 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Alex - 2016-11-29 22:55:00</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>This is a good article, as far as it goes.  It'd be great to see a similar article for setting up an NSDocument scenario.  There's a lot more going on, so it's not entirely clear to me how all the pieces fit together.
&lt;br /&gt;
&lt;br /&gt;And of course, NSViewController recently got a lot more powerful, and NSStoryboard is new, so I'd love to hear your ideas on how to use them, too, if at all.  One-xib-per-window sounds good, but being able to set up a bunch of common operations straight from IB sounds good, too.  I think there's ways to let storyboards span multiple files, but I'm not clear on how that works.
&lt;br /&gt;
&lt;br /&gt;Cheers!</description><guid isPermaLink="true">62510cd2165a9d3fab3cbbb01b9b00dd</guid><pubDate>Tue, 29 Nov 2016 22:55:00 GMT</pubDate></item><item><title>mikeash - 2015-09-29 21:02:04</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>If you create a text editor, do you create a separate nib for each of the quintillion possible documents your users might write? Of course not. You make &lt;i&gt;one&lt;/i&gt; nib for &lt;i&gt;one&lt;/i&gt; window which is able to contain and display arbitrary documents.
&lt;br /&gt;
&lt;br /&gt;Likewise, for alerts, you'd create one nib and one window controller for a single alert window that is configurable to show the hundred possible alert messages you have in your app. And of course this is so common that Apple has already done this for you with &lt;code&gt;NSAlert&lt;/code&gt;.
&lt;br /&gt;
&lt;br /&gt;Don't search for problems, search for solutions.</description><guid isPermaLink="true">34b149d1730617861ab265a336bf43b4</guid><pubDate>Tue, 29 Sep 2015 21:02:04 GMT</pubDate></item><item><title>Motti Shneor - 2015-09-29 20:02:20</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>What about nsalert sheet windows I need over my window? Do I need to create a separate nib for each of the hundred possible dialog alerts I have in my App?</description><guid isPermaLink="true">f293ad5c323939a48dd89b12fc49c77b</guid><pubDate>Tue, 29 Sep 2015 20:02:20 GMT</pubDate></item><item><title>7stud - 2015-05-29 00:04:58</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>What about cleanup under ARC?  
&lt;br /&gt;
&lt;br /&gt;1.  The user closes the window.
&lt;br /&gt;2.  How do you release the WindowController?</description><guid isPermaLink="true">acd978c64c2339aa3b1faf4a0202b285</guid><pubDate>Fri, 29 May 2015 00:04:58 GMT</pubDate></item><item><title>HB - 2013-08-26 20:17:27</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>Guess I'm a couple months late discovering this very helpful explanation of NSWindowControllers. 
&lt;br /&gt;My code was very similar but you have some better stuff so I changed my code to match. :-)
&lt;br /&gt;
&lt;br /&gt;One instance of the controller works just fine but I can't seem to have multiple instances at the same time. 
&lt;br /&gt;The &lt;code&gt;[_importantThingControllers addObject: controller];&lt;/code&gt;
&lt;br /&gt;part of your tutorial doesn't work for me. The window pops up briefly and then disappears. 
&lt;br /&gt;Not sure what the problem is and it's getting irritating.
&lt;br /&gt;Help appreciated!
&lt;br /&gt;
&lt;br /&gt;</description><guid isPermaLink="true">f8aef102cabaad89886c4815d39c7036</guid><pubDate>Mon, 26 Aug 2013 20:17:27 GMT</pubDate></item><item><title>jamie - 2013-04-27 00:04:05</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>"Do you not recommend creating windows programmatically? I've been moving to the 1 window, 1 window controller approach but skipping the xib file."
&lt;br /&gt;
&lt;br /&gt;I'd be curious to see examples of this, I know you can do it, but I wonder what best practices are:  should you do it in the view class, in another class that "decorates" the view, do you do it at init time or show time, shortcuts for setting up bindings, etc...</description><guid isPermaLink="true">4a06c54cade4bdf92b9fe8cc1a27a3d2</guid><pubDate>Sat, 27 Apr 2013 00:04:05 GMT</pubDate></item><item><title>Allen - 2013-04-17 17:29:14</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>Do you not recommend creating windows programmatically?  I've been moving to the 1 window, 1 window controller approach but skipping the xib file.</description><guid isPermaLink="true">675fdb174db2683515fc441579feb14e</guid><pubDate>Wed, 17 Apr 2013 17:29:14 GMT</pubDate></item><item><title>Marc Haisenko - 2013-04-16 07:59:41</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>s/should be called/should not be called/</description><guid isPermaLink="true">2433017658f74261a4d2c874e70666d4</guid><pubDate>Tue, 16 Apr 2013 07:59:41 GMT</pubDate></item><item><title>Marc Haisenko - 2013-04-16 07:58:43</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>Nice article. But I prefer a different "guard" for methods that should be called by users: the __attribute__((unavailable("A description string"))).
&lt;br /&gt;
&lt;br /&gt;In your class interface, do:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil __attribute__((unavailable("Use 'init' instead!")));
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;The advantage is that the compiler issues a warning/error at compile time rather than getting an exception at runtime.
&lt;br /&gt;</description><guid isPermaLink="true">b0c6b0b7a6d4fff91d99a256d146823b</guid><pubDate>Tue, 16 Apr 2013 07:58:43 GMT</pubDate></item><item><title>Anonymous - 2013-04-15 04:34:43</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>@MikeAsh: Allan reminded me a possible Q&amp;amp;A topic, the NSController methods. I've never understood that class and assumed it's not really useful ever. Is this true? If not, how is it to be used?</description><guid isPermaLink="true">6516bcb20b0d49906f500b827a6bc65b</guid><pubDate>Mon, 15 Apr 2013 04:34:43 GMT</pubDate></item><item><title>Ian - 2013-04-14 12:10:24</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>@jamie: Maybe Mike will pick up the mantle and take on that topic, but I've tried making my own Xcode templates, and my experience was that it was SO painful as to not be worth it.  And I even make lots of new projects (part of my normal workflow)...  The cure is worse than the disease.</description><guid isPermaLink="true">4682f73d9aad94aa323bc2119ec4ee60</guid><pubDate>Sun, 14 Apr 2013 12:10:24 GMT</pubDate></item><item><title>Allan Odgaard - 2013-04-11 19:01:16</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>It’s worth mentioning that prior to 10.8 it was not possible to make a weak reference to &lt;code&gt;NSWindowController&lt;/code&gt; objects. This is an issue when you want the window controller to be the delegate of an object in the view hierarchy (where the property should be weak). I believe that all Apple’s classes use “unsafe unretained”, so it’s only a problem with custom classes.
&lt;br /&gt;
&lt;br /&gt;Also worth mentioning that &lt;code&gt;NSWindowController&lt;/code&gt; does not descend from &lt;code&gt;NSController&lt;/code&gt; or implement the &lt;code&gt;NSEditorRegistration&lt;/code&gt; protocol, this means you generally need to bind the views’ properties to an intermediate &lt;code&gt;NSObjectController&lt;/code&gt; (where the window controller is set as the content) to have the commitEditing and discardEditing methods.
&lt;br /&gt;
&lt;br /&gt;Lastly, I am surprised that you stress the need for a xib. Since embracing auto-layout I am moving more and more of my GUI from xib files into source form. The advantages of having your GUI in code are many: version controllable, easier to refactor, ability to cut, copy and paste GUI code, no need to sync class info between code and GUI editor (with a lot of run-time errors eliminated related to this), and everything is 100% explicit and searchable.
&lt;br /&gt;</description><guid isPermaLink="true">cb62c6862886cc52b6e41e3c4522b336</guid><pubDate>Thu, 11 Apr 2013 19:01:16 GMT</pubDate></item><item><title>Benedict Cohen - 2013-04-09 08:44:45</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>It's worth noting that "one window = one nib + one NSWindowController subclass" is conceptual similar to the default iOS approach for view controllers. </description><guid isPermaLink="true">0106b16e7bc96c5ad308c85cdfa05d7b</guid><pubDate>Tue, 09 Apr 2013 08:44:45 GMT</pubDate></item><item><title>Mark Aufflick - 2013-04-09 02:15:12</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>Of course the other way to deal with the property/lazy loading issue is to use bindings. In the simple example given, you can just have regular NSString properties, and then bind the NSTextField stringValue to it.</description><guid isPermaLink="true">832149ec551761eb64b301b786810c45</guid><pubDate>Tue, 09 Apr 2013 02:15:12 GMT</pubDate></item><item><title>jamie - 2013-04-08 16:58:59</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>"Apple does a grave disservice to new Cocoa developers with their poorly constructed Xcode templates."
&lt;br /&gt;
&lt;br /&gt;Here's a Q&amp;amp;A topic: How can I create my own Xcode templates for files and subclasses?</description><guid isPermaLink="true">6a2cb2c5db6b35d26fa77e02feb5adca</guid><pubDate>Mon, 08 Apr 2013 16:58:59 GMT</pubDate></item><item><title>Peter Huber - 2013-04-06 12:31:57</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>Great article and thanks: I could never think of a situation where I would actually use the default initWithWindow: call that XCode's template provides, but I always kept it around "just in case". I guess I figured that there must be a profoundly logical reason why Apple chose to provide it and that one day I would have a revelation, then go back and refactor all my old code :-).</description><guid isPermaLink="true">98f4409bb4176476d1362d4e991d2eab</guid><pubDate>Sat, 06 Apr 2013 12:31:57 GMT</pubDate></item><item><title>Ken Thomases - 2013-04-06 06:58:21</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>Thanks for writing this. I strongly concur with your thesis. Apple does a grave disservice to new Cocoa developers with their poorly constructed Xcode templates.</description><guid isPermaLink="true">e1dbf6b91aec22aef431dd8d6c0d69ba</guid><pubDate>Sat, 06 Apr 2013 06:58:21 GMT</pubDate></item><item><title>Anonymous - 2013-04-06 00:41:48</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>Are there any downsides to just skipping the init methods and overriding &lt;code&gt;-(NSString*)windowNibName&lt;/code&gt;?
&lt;br /&gt;
&lt;br /&gt;Also, to avoid the problem you mentioned of the window not yet being loaded, I usually just use bindings. For example, for a simple login panel, I'll have two public NSString @properties on my NSWindowController subclass, named 'username' and 'password', and in my window I just bind the text fields to them. Bindings work beautifully for solving this problem.</description><guid isPermaLink="true">97ee190925e5a024429c6bddcf6035cd</guid><pubDate>Sat, 06 Apr 2013 00:41:48 GMT</pubDate></item><item><title>Ari Weinstein - 2013-04-05 20:12:26</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>Well huh. I've been writing Mac apps for a while, and I only use NSWindowController sometimes... and I often bundle a bunch of windows into MainMenu. Good points here, though, I'll have to reconsider my ways.</description><guid isPermaLink="true">a944b4f754e431f017dcb8ab8070c40a</guid><pubDate>Fri, 05 Apr 2013 20:12:26 GMT</pubDate></item><item><title>Michaël Fortin - 2013-04-05 17:13:11</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>Phew! I've been doing it the right way.
&lt;br /&gt;
&lt;br /&gt;Interesting read as always, keep it up!</description><guid isPermaLink="true">2a4ce67dea5c7f26d1103921e4c83d72</guid><pubDate>Fri, 05 Apr 2013 17:13:11 GMT</pubDate></item><item><title>Anon - 2013-04-05 17:01:09</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2013-04-05-windows-and-window-controllers.html#comments</link><description>documneted -&amp;gt; documented
&lt;br /&gt;Nowe -&amp;gt; Now</description><guid isPermaLink="true">5bf5a9efaadf809b1393bb53e09d4390</guid><pubDate>Fri, 05 Apr 2013 17:01:09 GMT</pubDate></item></channel></rss>
