如何使用Xcode 7和8编译针对最新SDK的Swift代码?
NSURL API上某些方法的可空性在iOS 9和iOS 10之间发生了变化 例如,对于如何使用Xcode 7和8编译针对最新SDK的Swift代码?,xcode,swift,foundation,Xcode,Swift,Foundation,NSURL API上某些方法的可空性在iOS 9和iOS 10之间发生了变化 例如,对于URLByAppendingPathComponent函数,但是。使用#available是行不通的,因为它不是编译时检查 let appSupportURL = try! NSFileManager.defaultManager().URLForDirectory(.ApplicationSupportDirectory, inDomain: .UserDomainMask, appropriate
URLByAppendingPathComponent
函数,但是。使用#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为目标?在2016年WWDC上,Ewa Matejska: 这项技术也很有用
#if swift(>=2.3)
// code that builds against iOS 10 SDK.
#else
// code that builds against iOS 9 SDK.
#endif