Conditional compile based on Xcode version
<p>I've built a plug-in for Xcode that primarily gets deployed through Alcatraz. This utility grabs the source for my plug-in from GitHub, compiles it, and, if successful, installs it in the proper directory. It has worked quite well until version 7.3 of Xcode was released with Swift 2.2.</p>

<p>Swift 2.2 introduced a new way of specifying selectors. Previously you would supply a string with the name of the function such as this:</p>

<pre><code>NSNotificationCenter.defaultCenter().addObserver( self, selector: "applicationFinishedLoading:", name: NSApplicationDidFinishLaunchingNotification, object: nil )
</code></pre>

<p>However the new method uses the #selector like so:</p>

<pre><code>NSNotificationCenter.defaultCenter().addObserver( self, selector: #selector(ColorSenseRainbow.applicationFinishedLoading(_:)), name: NSApplicationDidFinishLaunchingNotification, object: nil )
</code></pre>

<p>If I convert my code over to the new method then any people that are using previous versions of Xcode (7.2.1 and older) won't be able to use my plug-in because it doesn't know about the new #selector. I know this because I did convert it to get rid of the deprecation warnings and I got feedback from my users. However it is probable that the next version of Xcode will move to Swift 3 and I will have to make this change.</p>

<p>So my preferable path is to find a way to have the compiler choose the code applicable for the version of Xcode.  Something like this pseudo-code.</p>

<pre><code>#if (XCode_Version &gt;= 7.3)
    // use @selector ( ThisClass.functionName)
#else
    // use selector: "functionName:"
#endif
</code></pre>

<p>I know that there is swift() function that can be used to tell the version but that was only introduced with Swift 2.2 and if I use that the compilation will fail on Xcode 7.2.1 and below. This leaves me in the same place as before with the @selector function.</p>

<p>The other option is to take the release that I'm about to do and make it the last one with the selector: "functionName:" method. I'll then have a copy of that pre-compiled up on GitHub for users of older versions of Xcode to download and install manually.</p>

<p>Thanks for your help.</p>