Imran Sh
Imran Sh

Reputation: 1774

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. I want to create app for last version of iOS (9.0) but with support of 2 older versions like 8 and 7.

Base SDK: Latest (iOS 9.0)

Deployment: 7

I used UIAlertController and it's not available in iOS 7, So I can't build my project and I get error:

'UIAlertController' is only availble on iOS 8.0 or newer

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.

I'm confused and don't know must to create some target for each version of iOS or some project or 1 project!!!

Upvotes: 1

Views: 202

Answers (1)

Adam
Adam

Reputation: 26917

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
    }

Upvotes: 3

Related Questions