因为我的构建机器仍然使用Xcode12.5,所以UITabBar的scrollEdgeAppearance(它将不存在于Xcode12.5的SDK中)将使构建失败,即使我使用@available进行检查。
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;
}所以有没有可能做这种SDK签入代码,当构建SDK不是最新的SDK时,这些代码将不会参与构建?像这样
if (BuilDSDK >= someversion)
{
[UITabBar appearance].scrollEdgeAppearance = tabBarAppearance;
}发布于 2021-08-26 15:45:04
@available是一种运行时可用性检查,在这种情况下不能真正用于编译时的内容。
在Objective-C中,您可以将iOS 15SDK上应用的代码部分封装到另一个宏条件中:
#ifdef __IPHONE_15_0
if (@available(iOS 15.0, *)) {
...
} else {
#endif
// possible legacy branch code
#ifdef __IPHONE_15_0
}
#endif__IPHONE_15_0是从iOS 15 SDK开始定义的,因此在Xcode12/iOS 14 SDK中构建时会被省略。?
发布于 2021-10-15 11:20:21
Swift类的另一个类似的解决方案可以在这里找到:https://stackoverflow.com/a/69583441/1195661
#if swift(>=5.5) // Only run on Xcode version >= 13 (Swift 5.5 was shipped first with Xcode 13).
if #available(iOS 15.0, *) {
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
}
#endifhttps://stackoverflow.com/questions/68798163
复制相似问题