5

today i met with issue on Xcode 12. When i tried iOS 15 version of app i noticed that tabbar background changed. I solved this by adding this line of code

if (@available(iOS 15.0, *)) {
    [[UITabBar appearance] setScrollEdgeAppearance:tabBarAppearance.appearance];
}

But after I swapped back to Xcode 12 from Xcode 13 i got this issue.

No visible @interface for 'UITabBar' declares the selector 'setScrollEdgeAppearance:'

Seems like Xcode12 bug for me but maybe i am wrong.

Edit: added if statement which was in code

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Roman Varga
  • 101
  • 1
  • 4
  • It is available from iOS 13 only - `UINavigationBarAppearance *scrollEdgeAppearance UI_APPEARANCE_SELECTOR API_AVAILABLE(ios(13.0));` – Asperi Sep 10 '21 at 15:29
  • Its more about xcode build failed. When i switch to xcode 13 everything works. And i need this line just for ios 15 but cant build it in xcode 12. – Roman Varga Sep 10 '21 at 16:07
  • @Asperi `scrollEdgeAppearance` on `UINavigationBar` is not the same as `scrollEdgeAppearance` on `UITabBar`. `UINavigationBar` has had it since iOS 13.0. `UITabBar` had it added in iOS 15.0. – Daniel Storm Sep 22 '21 at 15:33
  • 1
    You'll want to do this compile time check: https://stackoverflow.com/a/68941618/2108547 – Daniel Storm Sep 22 '21 at 15:45
  • Ye i added empty function to UITabBar for xcode 12 and it solved the problem for me – Roman Varga Sep 22 '21 at 15:48

3 Answers3

4

The only solution that worked for us in a swift-file:

#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
        }
#endif

That snippet makes sure it is only compiled with Xcode Version > 13 and only runs for iOS 15. Swift 5.5 was introduced with Xcode 13.

palme
  • 2,499
  • 2
  • 21
  • 38
1

I think that's because scrollEdgeAppearance was just a property of UINavigationBar for iOS < 15 versions. Since iOS 15 They've extended it to all others navigation bars

As per Apple doc:

When running on apps that use iOS 14 or earlier, this property applies to navigation bars with large titles. In iOS 15, this property applies to all navigation bars.

Alastar
  • 1,284
  • 1
  • 8
  • 14
  • Yes i understand its new property/method and i need it only for ios 15 version. But if i add the mentioned line xcode build fail because cant find the method. In xcode 13 everything works fine. Its strange for me that they dont support xcode 12 with that method. – Roman Varga Sep 10 '21 at 16:05
  • 1
    That's because Xcode 12 doesn't support iOS 15 – Alastar Sep 13 '21 at 07:14
1

It's only available in Xcode 13. So we did this to fix the issue and be able to compile on both Xcode 12 and 13:

#if __clang_major__ >= 13
if (@available(iOS 15.0, *)) {
    [[UITabBar appearance] setScrollEdgeAppearance:tabBarAppearance.appearance];
}
#endif
karlingen
  • 13,800
  • 5
  • 43
  • 74