On Apr 9, 2008, at 11:08 PM, Ben Lachman wrote:
On Apr 9, 2008, at 3:27 PM, David Duncan wrote:
On Apr 9, 2008, at 7:43 AM, Lorenzo Bevilacqua wrote:

I'm trying to build a Cocoa application so that it can run on Mac OS X from version 10.3.9 to 10.5. I have 10.5 installed so the application runs fine on my system and on other Leopard systems. I haven't build a project for multiple platforms yet, so I tried to duplicate the main Xcode target and set different deployment target settings like

Typically you would only use 1 target. Use the SDK to the OS whose API your are targeting (such as the 10.5 SDK). Then set the deployment target to the minimum version you wish to run on (example, 10.3). Finally, you would do runtime checks for API availability.

This is totally true. Multiple binaries make unhappy users. Of course buggy cross-version binaries make unhappy users too.

- Is there a way to differentiate part of code by platform? I remember I saw in some files lines like this

#if MACOSX_DEPLOYMENT_TARGET == MAC_OS_X_VERSION_10_4
#endif

is this correct?

This is a compile time check. Generally it is appropriate if you plan to ship a binary with a specific compile-time dependency. It sounds like you really want a run time check, which requires you to check for the availability of the features you are trying to use. How you check for this will depend on what you are doing to some degree.


To elaborate:

Your code will have checks like this in it:

if( [someObject respondsToSelector:@selector (niftyLeopardFeatureMethod:)] )
        [someObject niftyLeopardFeatureMethod:anotherObject];
else
        // handle the 10.4 and/or 10.3.9 case

Actually, what I find to be a better arrangement is something like this:

#if MACOSX_DEPLOYMENT_TARGET < MAC_OS_X_VERSION_10_5
if (![someObject respondsToSelector:@selector (niftyLeopardFeatureMethod:)])
{
    // handle the pre-10.5 case here
}
else
#endif
{
    // handle the 10.5+ case here
}

Picky, perhaps, but the benefit is that the check for existence of a 10.5 feature, plus the code that handles the older OS versions, is inside a compile-time conditional. If you later change your deployment target to 10.5, all the older OS pieces are compiled out. You can also easily search your sources for "MACOSX_DEPLOYMENT_TARGET" to find your legacy code.

One caveat, though, is that you should probably have a runtime check for the minimum OS version you expect so that you don't end up with a crash if someone tries to use your nifty Leopard features on Tiger. Adding something to main() would probably be easiest, either checking against NSAppKitVersionNumber or calling Gestalt() to get the OS version.

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 [EMAIL PROTECTED]

Reply via email to