1

As i am learning OS X development and here i came across strange situation where i need to find out a way to build the app for target above 10.6 and if it is 10.7 then i need to call some newly added methods or enums. May be there is no such way but thought to ask it.

I guess there must be way to use it via Macros or something similar. I don't want to create OS specific builds. Any help will be appreciated. May be there is no such way but thought to ask it.

Regards, M P.

2 Answers 2

1

One approach is to compare NSFoundationVersionNumber with NSFoundationVersionNumber10_* -- see Foundation/NSObjCRuntime.h for the available versions.

Sometimes, you can try -[NSObject respondsToSelector:].

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for pointing it out but i also have to make use of 10.7 enums so i guess i will have to use #ifdefine and then add methods those make use of those enums. Using if define, i goess will not generate compile time error.
@MP if you set the SDKROOT to 10.7, then you can build with those headers and enums visible.
0

You can read the version from the property file:

 /System/Library/CoreServices/SystemVersion.plist 

In this way, you can build dynamic code without different versions by #ifdefine

EDIT: @MP Well, I understood that you do not want to generate version specific code. If you ready to do so, then it is quite easy. Simply use:

 #include <Availability.h> #ifdef __MAC_10_7 /* 10.7 only code */ #else /* not 10.7 code */ #endif 

2 Comments

Thanks for the response. So you mean with the help of i #ifdefine i can make use of 10.7 specific enum and methods and then compile it for target above 10.6? Any example of #ifdefine will be helpful.
Actually, you are not guaranteed to be able to use the __MAC_10_7 macro reliably for this purpose. While the current SDKs before 10.7 don't define this constant, the latest version of the 10.4 SDK defines __MAC_10_5 as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.