Search code examples
objective-ccocoabackwards-compatibility

10.5 base SDK, 10.4 deployment: how to implement missing methods


I have a project that targets both Mac OS X 10.4 and 10.5, where 10.5 is the base SDK.

Some methods like -[NSString stringByReplacingOccurrencesOfString:withString] are unavailable in 10.4. I could just implement the functionality by hand. Another option would be to implement the method as a category, but that would mess with the 10.5 implementation and that's something I'd like to avoid.

So how do I implement such methods in 10.4 without messing up 10.5 and in such a way that I can take out the implementation easily when I decide to stop supporting 10.4?


Solution

  • I think you have to use +load and +initialize to load a method at runtime if the method doesn't already exists.