0

How can I translate the following code snippet from Swift to Objective-C?

#if compiler(>=5.5)
if #available(iOS 15.0, *) {
    myTableView.sectionHeaderTopPadding = 0.0
}
#endif

Alternatively, is there any macro in objective c side that assists to know the compiler version?


Cy-4AH suggested and answer that used,

#ifdef __IPHONE_13_0
if (@available(iOS 13.0, *)) {
    ...
}
#endif

However, in my case #ifdef __IPHONE_15_0 is not available in Xcode 12.x.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256

1 Answers1

1

I have managed to solve this problem with a workaround discussed here.

#if __clang_major__ >= 12
    NSLog(@"My Objective-C language support is what Apple Clang/Xcode 12.x can support.");
#endif

Note that the clang_major, clang_minor, etc. variables resemble (are almost the same as) the Xcode versions and need careful investigation before usage.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256