10.5 Basic SDK, 10.4 Deployment: How to Implement Missing Methods
I have a project targeting both Mac OS X 10.4 and 10.5, where 10.5 is the base SDK.
Some methods, such as -[NSString stringByReplacingOccurrencesOfString:withString]
, are not available in 10.4. I could just implement the functionality manually. Another option is to implement the method as a category, but that will be useless with the 10.5 implementation and which I would like to avoid.
So how do I implement such techniques in 10.4 without the hindrance of 10.5 and in such a way that I can easily implement the implementation when I decide to drop support for 10.4?
a source to share
I think you should use +load
and+initialize
to load a method at runtime if that method doesn't already exist.
a source to share
Use a category, but put the tag in the method name; eg stringByReplacingOccurrencesOfString_TigerCompatible:
. In the implementation, call either the Leopard implementation or your own.
When you only go to Leopard, do a project search for "TigerCompatible", then write down all of these methods and de-tag all of your calling sites.
a source to share
How do I use a C preprocessor macro to insert the appropriate methods if it is generated for 10.4? Maybe try doing something like this in a category so those methods that don't exist in 10.4 are only included if they are built for 10.4?
#if defined(MAC_OS_X_VERSION_10_4) && MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
// Put your implementations of the methods here
#endif
a source to share
Do you need to support 10.4? If you are only using 10.5 methods in the main parts of your application, it might be time to think about moving to 10.5 only.
Anyway, with the specific example above, I would suggest to abandon that and make a mutable copy of your string so that you can use a similar method for NSMutableString that works in 10.4
a source to share