This may seem like a silly post, but I have been talking to PC developers working on Mac OS code who are creating code like they are still working on the PC. So this is a note for them; things they should keep in the back of their mind when they are coding.
Mac OS SDKs
When using different SDK’s in Mac OS Programming, there are ways for checking what SDK you have available.
At build time, you can use the macros provided by Apple to check what’s available:
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
#endif
Checking for functionality
At runtime, if you are crossing library boundaries and calling a library that you didn’t build, you should check that the class you are sending a message to responds to that message by calling the respondsToSelector method. You can at that point decide what path to take, which is better then calling the method and proceeding with your code as if the previous call succeeded:
- (void)hornMethod
{
if ( [m_windClass respondsToSelector:@selector(blowThatHorn)] )
{
[m_windClass blowThatHorn];
}
}