The advice from Apple is to always set the Base SDK for iPhone/iPad projects to the latest installed version of the OS. At the current time this would be iOS 4.0, although 4.0 is only just about to be released so the vast majority of users will still be using 3.X. Obviously there will be features and functions available in 4.0 which don’t exist in 3.X, however I would still like to support 3.X users for obvious reasons.
Suppose I am using some 4.0 specific features. If my Base SDK is set to 4.0 and my deployment target is set to 3.1.X, my project will compile just fine. However, unless I’ve got specific code in there testing to see if certain features can be used, I will experience a crash on 3.1.X.
But what if I don’t know that this function doesn’t exist in 3.1.X? Will I only find this out by experiencing a crash on that particular screen? What if the function is buried deep within my app, or only appears in very specific situations? Or what if I’m a new developer who starts coding on 4.0, and doesn’t really know the ins and outs of 3.X? I suppose the obvious answer would be to set the deployment target for 4.0, but I suspect a lot of end users will be sticking on 3.1.X for a while so that’s not ideal.
Am I missing something about how this all works? Of course I need to test my app fully in 3.1.X, but it seems crazy that I don’t get any sort of compiler assistance. It’s really not that inconceivable that something will slip through at some point. Perhaps I can temporarily set the Base SDK back to 3.1.X every now and again?
There are two variables here: there’s the base SDK and the deployment target.
You set the base SDK to the lowest version of the SDK that has all the features that you want to use. For example, if you have an iPad application that also runs on an iPhone, you’d set the base SDK to 3.2.
The deployment target is the lowest version that your app will run on. So in the above example you’d set the target to something like 3.0.
To use classes that are in some versions of the SDK but not others there are a bunch of methods/functions, such as
NSClassFromStringandrespondsToSelector:.And how do you know which methods exist in each version? Well, the documentation tells you when each method was introduced and if/when it was deprecated. Of course you also need to test the code.