Re: Determining OS at Runtime
Re: Determining OS at Runtime
- Subject: Re: Determining OS at Runtime
- From: Steve Christensen <email@hidden>
- Date: Fri, 03 Jul 2009 10:06:25 -0700
For the case of a function, if you're deploying on 10.4 but using a
10.5 function, that function will be weak-linked so doing a runtime
check is both faster and more accurate in determining whether a
function exists or not. For a Cocoa class method, you could replace
the test with a call to -respondsToSelector: to determine if it
exists or not. In both cases you're taking a feature-based approach
rather than a "I know this feature showed up in this OS version"
approach.
And if you did actually need a IsLeopardOrLater function, it would be
better to cache the Gestalt result once since it won't change while
your app is running. Otherwise you're making a selector value lookup
each time.
BOOL IsLeopardOrLater(void)
{
static SInt32 sVersion = 0;
if (sVersion == 0)
Gestalt(gestaltSystemVersion, &sVersion);
return (sVersion >= 0x1050);
}
On Jul 3, 2009, at 9:00 AM, Mark Munz wrote:
You might also just use Gestalt:
BOOL IsLeopardOrLater(void)
{
SInt32 vers;
Gestalt(gestaltSystemVersion,&vers);
return (vers >= 0x1050);
}
On Fri, Jul 3, 2009 at 6:59 AM, Steve Christensen<email@hidden>
wrote:
On Jul 2, 2009, at 9:56 PM, Andrew Farmer wrote:
On 2 Jul 2009, at 16:29, Steve Christensen wrote:
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();
Preprocessor directives take effect at compile time, not at runtime.
Yes, I'm aware of that. My point was that by writing the code in this
fashion, when you start building your software to -require- a
minimum of
10.5, any pre-10.5 code will be compiled out because then
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 so all
you're left
with is the call to SomeLeopardFunction().
_______________________________________________
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