2016-06-22 31 views
2

對NSURL API一些方法中,可爲空的iOS 9和10如何編譯針對使用Xcode 7和8的最新SDK的Swift代碼?

例如,iOS 10 returns an optional之間改變爲URLByAppendingPathComponent功能但iOS 9 does not。使用#available不會起作用,因爲它不是編譯時檢查。

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) 
    } 

我該如何使用Xcode 7或Xcode 8在我的應用程序中構建Swift代碼,同時仍然定位最新的iOS SDK?

回答

相關問題