How to compile Swift code targeting the latest SDKs using Xcode 7 and 8?
<p>The nullability of some methods on the NSURL API changed between iOS 9 and 10.</p>

<p>For example, <a href="https://developer.apple.com/reference/foundation/nsurl/1413953-urlbyappendingpathcomponent" rel="nofollow">iOS 10 returns an optional</a> for the <code>URLByAppendingPathComponent</code> function but <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/#//apple_ref/occ/instm/NSURL/URLByAppendingPathComponent:isDirectory:" rel="nofollow">iOS 9 does not</a>. Using <code>#available</code> isn't going to work because it is not a compile time check.</p>

<pre><code>    let appSupportURL = try! NSFileManager.defaultManager().URLForDirectory(.ApplicationSupportDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
    let folder: NSURL
    if #available(iOS 10.0, *) {
        folder = appSupportURL.URLByAppendingPathComponent("Folder", isDirectory: true)!
    } else {
        folder = appSupportURL.URLByAppendingPathComponent("Folder", isDirectory: true)
    }
</code></pre>

<p>How can I build the Swift code in my app with both Xcode 7 or Xcode 8 while still targeting the latest iOS SDKs?</p>