On Jul 1, 2009, at 5:22 PM, Sherm Pendley wrote:

On Wed, Jul 1, 2009 at 7:24 PM, iseecolors<iseecol...@sbcglobal.net> wrote:
I need to support 10.4 in my application, but it uses some Carbon APIs that are deprecated in 10.5 and I am using some new 10.5 APIs that require the
10.5 SDK.

I am sure I have seen this before, but I have been unable to find it in the Archive. How do I determine at runtime which OS version I am running on?

Just check for the presence of the function you want to call. In
Xcode, set your deployment target to 10.4, so that Leopard-only
symbols will be weak-linked. Then just check the symbol for NULL
before calling it:

    if (SomeLeopardFunction != NULL) {
        SomeLeopardFunction();
    } else {
        TigerFunction();
    }

If you want to make sure that you don't include any "old" code in your executable when you decide to make 10.5 (for example) your base OS version, you could arrange your code like this:

#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
    if (SomeLeopardFunction == NULL)
        TigerFunction();
    else
#endif
        SomeLeopardFunction();

...then the compiler will take care of sorting out the details for you. If you use that sequence in several places, it might even be worthwhile to create an inline wrapper function in a header file so the OS-specific details are kept in one place:

inline void SomeFunction()
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
    if (SomeLeopardFunction == NULL)
        TigerFunction();
    else
#endif
        SomeLeopardFunction();
}


steve

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to