如何在Xcode和Swift中使用不受支持的类(新功能)构建项目 [英] How to build project with unsupported class (new feature) in xcode and swift
问题描述
我是Apple平台的新手,我从xcode 7和swift开始.我想为iOS的最新版本(9.0)创建应用程序,但要支持8和7等2个旧版本.
I'm new in Apple platform and I started with xcode 7 and swift. I want to create app for last version of iOS (9.0) but with support of 2 older versions like 8 and 7.
基本SDK :最新版(iOS 9.0)
Base SDK: Latest (iOS 9.0)
部署:7
我使用了UIAlertController,它在iOS 7中不可用,所以我无法构建我的项目,并且出现错误:
I used UIAlertController and it's not available in iOS 7, So I can't build my project and I get error:
'UIAlertController'仅在iOS 8.0或更高版本上可用
'UIAlertController' is only availble on iOS 8.0 or newer
我的问题不仅是此类,我还在寻找一种解决方案以弄清楚如何处理多版本设备的应用程序.我还阅读了一些不错的文章,例如此,但我需要有关xcode 7的更多信息和技术,而不是Swift而不是Objective-c或旧版本的xcode.
My problem isn't just this class, I looking for a solution to figure out how to handle multi version-device app. Also I read some good article like this but I need more info and technique about xcode 7 and swift not objective-c or old versions of xcode.
我很困惑,不知道是否必须为每个iOS版本或某个项目或一个项目创建一些目标!!!
I'm confused and don't know must to create some target for each version of iOS or some project or 1 project!!!
推荐答案
您可以使用 if #available
子句在运行时检查iOS版本.在您的情况下,它将如下所示:
You can use if #available
clause to check iOS version at runtime. In your case it will look like following:
if #available(iOS 8.0, *) {
//use UIAlertController
}
else {
//use UIAlertView
}
这篇关于如何在Xcode和Swift中使用不受支持的类(新功能)构建项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!