Reputation: 2235
For my app, I want to support for iOS7 and iOS8. I have set the deployment target to iOS7, however Xcode does not highlight to me methods which are only available on iOS8 (causing the app to crash in iOS7, example using [NSString containsString]).
In Android Studio, if you have set the minSDK, it shows you a warning if you are using methods that are only added in newer versions. I have tried searching around, but I can't really seem to find anything useful. I feel I might be missing something basic here.
Upvotes: 1
Views: 222
Reputation: 700
Probably one can try to compile the project with earlier version of base SDK. Then it should show the code that does not work in earlier iOS versions. Though XCode includes only latest SDK. So needed SDK needs to be downloaded and copied to appropriate directory. Something like that: https://stackoverflow.com/a/12523971/550656
Upvotes: 0
Reputation: 3
You could just replace
[stringA containsString:stringB]
with
[stringA rangeOfString:stringB].location != NSNotFound
This will check if the location is equal to NSNotFound to know if a string contains another string.
Upvotes: 0
Reputation: 5326
There is no way to know if you are using a new function without support of old iOS version. The only way is to check the availability of them in the documentation :(.
In order to write a code that changes between iOS versions add global variable or define:
#define IS_UNDER_IOS_8 ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0)
use it like this:
if (IS_UNDER_IOS8) {
}
else {
}
Upvotes: 0
Reputation: 19790
This is how you do it:
if ([string respondsToSelector:@selector(containsString:)]) {
//Do your iOS 8 only code.
}
Upvotes: 1
Reputation: 2979
if ( [object respondsToSelector:@selector(containsString:)] )
NSLog ( [object containsString:@"abc"]?@"WOOT!":@"darn..." )
Upvotes: 2