简体   繁体   English

如何在Xcode和Swift中使用不受支持的类(新功能)构建项目

[英]How to build project with unsupported class (new feature) in xcode and swift

I'm new in Apple platform and I started with xcode 7 and swift. 我是Apple平台的新手,我从xcode 7和swift开始。 I want to create app for last version of iOS (9.0) but with support of 2 older versions like 8 and 7. 我想为iOS的最新版本(9.0)创建应用程序,但支持2个旧版本,如8和7。

Base SDK : Latest (iOS 9.0) 基本SDK :最新(iOS 9.0)

Deployment : 7 部署 :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 7中不可用,所以我无法构建项目,并且出现错误:

'UIAlertController' is only availble on iOS 8.0 or newer “ UIAlertController”仅在iOS 8.0或更高版本上可用

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. 我也阅读了一些类似这样的好文章,但是我需要更多有关xcode 7的信息和技术,而不是迅速的Objective-C或旧版本的xcode。

I'm confused and don't know must to create some target for each version of iOS or some project or 1 project!!! 我很困惑,不知道是否必须为每个iOS版本或某个项目或一个项目创建一些目标!!!

You can use if #available clause to check iOS version at runtime. 您可以使用if #available子句在运行时检查iOS版本。 In your case it will look like following: 您的情况如下所示:

    if #available(iOS 8.0, *) {
        //use UIAlertController
    }
    else {
        //use UIAlertView
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM