1

I have tried to use such check to apply some code that should works only on previous versions of iOS before iOS 13 and it doesn't work correctly i.e. it is executed on iOS 13

if #available(*, iOS 12) { } 

I make a workaround like this

if #available(iOS 13, *) { /// Do nothing here } else { } 

But i have additional curly braces block

3 Answers 3

4

You can use guard statement

guard #available(iOS 13.0, *) else { // Code for earlier iOS versions return } 
Sign up to request clarification or add additional context in comments.

Comments

2

You can get the currentVersion of your OS using:

UIDevice.current.systemVersion 

Using this you can easily create your own method.

func SYSTEM_VERSION_LESS_THAN(version: String) -> Bool { return UIDevice.current.systemVersion.compare(version, options: NSString.CompareOptions.numeric) == ComparisonResult.orderedAscending } 

Comments

1

In Swift 5.6 (Xcode 13.3+), you can use #unavailable condition.

if #unavailable(iOS 13) { // This code will run on iOS 12.* and earlier } 

This is the proposal for reference: SE-0290.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.