Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally including headers depending on iOS version

I'm attempting to use a library which has a iOS5 and iOS4.3 flavours. The problem I'm having is getting the right version included conditionally, i.e:

for iOS5:

#include ios5stuff.h
@implementation
  // do stuff
@end

For iOS4

#include ios4stuff.h
@implementation
  // do stuff
@end

I can see how to conditionally include stuff within the class's implementation block, but not outside this. Can anyone suggest the best way of doing this?

like image 223
TimD Avatar asked Oct 11 '11 12:10

TimD


1 Answers

You should be able to do this (untested):

#import <Availability.h>

#if defined(__IPHONE_5_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
#import "my_header_for_io5_and_above.h"
#elif defined(__IPHONE_4_3) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_3
#import "my_header_for_ios4.3.h"
#else
#error Your SDK is too old ! Need at least 4.3.
#endif
like image 133
DarkDust Avatar answered Sep 25 '22 02:09

DarkDust