Because my build machine is still using the Xcode 12.5 , So the UITabBar’s scrollEdgeAppearance(which will not exist in the Xcode 12.5’s SDK) will make the build fail even i’am using the @available to check .
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance* navBarAppearance = [UINavigationBarAppearance new];
navBarAppearance.backgroundColor = [UIColor colorNamed:@"navbar_bg"];
[UINavigationBar appearance].standardAppearance = navBarAppearance;
[UINavigationBar appearance].scrollEdgeAppearance = navBarAppearance;
UITabBarAppearance* tabBarAppearance = [UITabBarAppearance new];
tabBarAppearance.backgroundColor = [UIColor colorNamed:@"second_bg"];
[UITabBar appearance].standardAppearance = tabBarAppearance;
[UITabBar appearance].scrollEdgeAppearance = tabBarAppearance;
[UITableView appearance].sectionHeaderTopPadding = 0;
}
So is it possible to do this kind of SDK checking in code ,when the build SDK is not the newest SDK , these code will not be involved to build? like this
if (BuilDSDK >= someversion)
{
[UITabBar appearance].scrollEdgeAppearance = tabBarAppearance;
}
2
Answers
@available
is a runtime availability check, not really usable for compile-time stuff in this situation.In Objective-C, you can wrap the code part applied on iOS 15 SDK into another, macro condition:
__IPHONE_15_0
is defined starting with iOS 15 SDK, thus being omitted when building in Xcode 12/iOS 14 SDK. 👍Another similar solution for Swift classes can be found here: https://stackoverflow.com/a/69583441/1195661: