• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Determining OS at Runtime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determining OS at Runtime


  • Subject: Re: Determining OS at Runtime
  • From: Steve Christensen <email@hidden>
  • Date: Thu, 02 Jul 2009 16:29:14 -0700

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

On Wed, Jul 1, 2009 at 7:24 PM, iseecolors<email@hidden> 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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Determining OS at Runtime
      • From: Andrew Farmer <email@hidden>
    • Re: Determining OS at Runtime
      • From: Steve Christensen <email@hidden>
    • Re: Determining OS at Runtime
      • From: Dave DeLong <email@hidden>
References: 
 >Determining OS at Runtime (From: iseecolors <email@hidden>)
 >Re: Determining OS at Runtime (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: Changing content of object inside NSMutableArray
  • Next by Date: Re: Determining OS at Runtime
  • Previous by thread: Re: Determining OS at Runtime
  • Next by thread: Re: Determining OS at Runtime
  • Index(es):
    • Date
    • Thread