serkanmalagic
serkanmalagic

Reputation: 81

How can I detect that there are parts of the code that do not match the ios version?

There are various features that I use in the project. For example, the stock pictures that come after iOS 12. For example, OTP feature after iOS 12

The application version is set to ios 11. But I want it to warn in the code. I can't see it

Can I get a message like "You have to open an if block to use this feature"?

Upvotes: 0

Views: 112

Answers (1)

skaak
skaak

Reputation: 3018

Xcode does provide these types of warnings?!

You should get something like 'feature is only available in iOS 12.0 or newer' when using something that is not available in the target iOS version. Those you need to guard with the usual

if ( @available( iOS 12, * ) )

and the warning will go away.

Based on comment

I assume based on the question you have your version set to 11 but based on your comment you need to set this correctly, e.g. in Xcode next to the target it should look something like this (for an iOS 10).

Target iOS version

If you use that you without the guard you should get a warning similar to this one

Xcode availability warning

The -Wunguarded-availability and -Wunguarded-availability-new compiler flags should be on (the default) but you can force this in the project's build settings under Other warning flags.

Update

I used Xcode 12.1 for this. Created a new default iOS project. Then in the target, select iOS 11 as shown below.

Target iOS project

Then to the view controller created by the project I added a text field, linked it as a property as shown below and immediately the warning that you are looking for popped up.

warning

Thanks Ol Sen Xcode setting

Based on Ol Sen's comment - yes, check that this is enabled. Should be by default. Note you can set it under the target, but as in the image, it is better to set this at the project level.

Xcode more settings

Upvotes: 2

Related Questions