ConditionalCoding

Latest

  • Dev Juice: Help me leverage Lion-only features

    by 
    Erica Sadun
    Erica Sadun
    08.29.2011

    Dear Dev Juice, I'm part of a tiny company developing iOS apps. We're about to develop our first Mac OS X app. There are many cool new features in MAC OS X Lion and we'd like to take advantage of these. However, this would mean only people on Lion could use our app... Do you think most people have upgraded to Lion? Or do you think we'd be ignoring a lot of potential users still on Snow Leopard? Gareth Dear Gareth Lots of users have made the jump to Lion but lots more have not. Rather than jumping on the Lion bandwagon completely by providing a Lion-only application, consider conditional coding instead. Conditional coding allows you to offer certain features only to Lion users while ensuring the application remains both 10.6 and 10.7 ready. This solution allows you to build your application for the greatest number of users. Make sure you clarify in your marketing text that certain features are Lion-only so you don't tick off either Apple or your user base. Here are a few conditional coding hints. Check for properties using key/value coding. If valueForKey: returns nil, the property is not available in Snow Leopard. Check for classes using NSClassFromString(). Code around non-existent classes in Snow Leopard by disabling features or removing inappropriate options. Check for selector compliance using respondsToSelector:. When newer APIS are supported, objects will report that they respond to those selectors, letting you call them without crashing the program. You may generate compile-time warnings about unimplemented selectors unless you use work-arounds like performSelector:withObject:. If you really want to go hard core, you can build NSInvocation instances directly. Happy Developing!