title: Using Swift with an OS X Preference Pane plugin
body: <p>I'd like to use Swift to build an OS X Preference Pane plugin for the System Preferences app, but I can't get it to work.</p>
  
  <p><a href="https://i.stack.imgur.com/cEAbz.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/cEAbz.jpg" alt="enter image description here"></a></p>
  
  <p>After clicking "Next" the Xcode template doesn't offer an option to choose Swift as a language, but automatically creates the project in Objective-C.</p>
  
  <p><a href="https://i.stack.imgur.com/AhHid.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/AhHid.jpg" alt="enter image description here"></a></p>
  
  <p><strong><em>Without adding any code</em></strong> or doing anything else, the project builds successfully. If you right-click on the Product and select "Open in External Editor", System Preferences will successfully install and load the preference pane.</p>
  
  <p><a href="https://i.stack.imgur.com/YXxV3.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/YXxV3.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/5StDh.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/5StDh.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/03YHS.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/03YHS.jpg" alt="enter image description here"></a></p>
  
  <p><strong><em>It just works!</em></strong> </p>
  
  <p>Well that's great, but now, I want to add a new Cocoa subclass using Swift. </p>
  
  <p><a href="https://i.stack.imgur.com/I401L.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/I401L.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/GIIPe.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/GIIPe.jpg" alt="enter image description here"></a></p>
  
  <p>Accepting the default, and allowing it to create the Bridging Header.</p>
  
  <p><a href="https://i.stack.imgur.com/HDUqK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/HDUqK.png" alt="enter image description here"></a></p>
  
  <p>Now, quit System Preferences and <strong><em>without adding any code</em></strong>, rebuild the project. As before, right-click the Product and "Open in External Editor".</p>
  
  <p>System Preferences will confirm replacing the preference pane, and it will install it, but then it fails to load.</p>
  
  <p><a href="https://i.stack.imgur.com/irXiw.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/irXiw.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/KHaK0.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/KHaK0.jpg" alt="enter image description here"></a></p>
  
  <p>If you show the built Product in the Finder, in addition to the .prefPane plugin, there's also a .swiftmodule folder.</p>
  
  <p><a href="https://i.stack.imgur.com/IE5QL.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/IE5QL.jpg" alt="enter image description here"></a></p>
  
  <p>I'm guessing there's something missing in the Build Phases or Build Settings that's responsible for incorporating the .swiftmodule with the rest of the bundle, but haven't been able to figure it out.</p>
  
  <p>After you add some code that uses the new class, it's necessary to import
  the Swift project umbrella header ("Prax-Swift.h") to make the project compile, but importing the umbrella header doesn't fix this problem.</p>
  
  <pre><code>//  Prax.h
  
  #import &lt;PreferencePanes/PreferencePanes.h&gt;
  #import "Prax-Swift.h"
  
  @interface Prax : NSPreferencePane
  
  @property PraxObject *ourPrax;
  
  - (void)mainViewDidLoad;
  
  @end
  </code></pre>
  
  <p>I also tried deleting Prax.h and Prax.m and simply implementing the NSPreferencePane subclass in Swift. As before, the project builds and installs, but System Preferences fails to load it.</p>
  
  <pre><code>//  Prax.swift
  
  import PreferencePanes
  
  class Prax: NSPreferencePane {
  
      override func mainViewDidLoad() {
  
      }
  }
  </code></pre>
  
  <p>Sorry if I've used too many pictures in this question; it seemed to be the clearest way to explain the problem and make it easy to reproduce. There's probably a simple solution. Any ideas?</p>