Building for 10.7 in Xcode 3
Building for 10.7 in Xcode 3
- Subject: Building for 10.7 in Xcode 3
- From: Jerry Krinock <email@hidden>
- Date: Sat, 23 Jul 2011 13:44:40 -0700
I was contacted off-list and asked if one can use Xcode 3 to produce apps that are "compatible with the current generations", which I interpret to mean will run in Lion and maybe use some Lion features. The short answer is yes.
Longer answer… You'll be using the 10.5 or 10.6 SDK. A problem arises when you want to use API which are new in Lion. Unless you're writing a 10.7-only app, you shouldn't have too many of these. To compile them without errors or warnings, you need to supply the declarations that are missing from your SDK. You'd also like to write your code in such a way that all the crap you add will be eliminated by #if when someday you compile with the 10.7 SDK.
Unless someone knows a better way…
For constants, you actually need to find out from the 10.7 SDK what their values are and define them. Here's an extreme example that works down to the 10.0 SDK, with a long comment that explains how it works…
// Constants defined in Mac OS X 10.7 SDK, defined here for compatibility with earlier SDKs.
/* This is kind of tricky because we're spanning multiple versions. We want to
know if the value is 1070 or greater.
Say, for example, that you're building with the 10.3 SDK. You will have
MAC_OS_X_VERSION_MIN_REQUIRED = 1030
MAC_OS_X_VERSION_10_6 = 0 (because it is not defined)
MAC_OS_X_VERSION_10_5 = 0 (because it is not defined)
MAC_OS_X_VERSION_10_4 = 0 (because it is not defined)
MAC_OS_X_VERSION_10_3 = 1030
MAC_OS_X_VERSION_10_2 = 1020
MAC_OS_X_VERSION_10_1 = 1010
MAC_OS_X_VERSION_10_0 = 1000
The above lines will evaluate to
1030 <= 0 false
1030 <= 0 false
1030 <= 0 false
1030 <= 1030 true
1030 <= 1020 false
1030 <= 1010 false
1030 <= 1000 false
Similarly for other SDKs
*/
#if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_6) \
|| (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5) \
|| (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4) \
|| (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3) \
|| (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_2) \
|| (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_1) \
|| (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_0)
NSString* const NSUndoManagerDidCloseUndoGroupNotification = @"NSUndoManagerDidCloseUndoGroupNotification";
NSString* const NSUndoManagerGroupIsDiscardableKey = @"NSUndoManagerGroupIsDiscardableKey";
#endif
For method names, you declare them in a category, giving the category a unique name such as DefinedInMac_OS_X_10_7. The compiler assumes that DefinedInMac_OS_X_10_7 is defined somewhere. It's not. Here's an example showing two methods you'll need to support Auto Save and Versions using the 10.5 or 10.6 SDK, in your NSDocument subclass.
#if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_6) \
|| (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5) \
/*!
@brief Declares a couple of methods that are defined in the 10.7 SDK,
to eliminate compiler warnings.
@details Be careful to only invoke super on these methods after
you've checked that you are running under Mac OS X 10.7.
*/
@interface NSPersistentDocument (DefinedInMac_OS_X_10_7)
- (BOOL)isInViewingMode ;
- (void)saveToURL:(NSURL *)url
ofType:(NSString *)typeName
forSaveOperation:(NSSaveOperationType)saveOperation
completionHandler:(void (^)(NSError *errorOrNil))completionHandler ;
@end
#endif
Of course, the disadvantage of all this cross-compiling is that must be very careful since the compiler is not going to catch any mistakes.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden