Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Xcode: Warn about methods not in minimum target SDK

Tags:

xcode

ios

sdk

Is there a way to have Xcode tell me when I'm calling a method that isn't available in the SDK of the minimum supported target?

For example, the method [NSURLConnection sendAsynchronousRequest:queue:completionHandler:]. This method is available on iOS5 and up. But my application's minimum target is iOS4.

If I use that method (sendAsync), I'd like Xcode to tell me that that method isn't available for the minimum target I'm trying to support.

I've tried putting __IPHONE_OS_VERSION_MAX_ALLOWED=40000 in the preprocessor settings, but that just triggers a bunch of Apple SDK errors that aren't helpful. (Probably because my active SDK is iOS5.1)

Is the only solution to get ahold of old SDKs and install them in Xcode?

Are there any easier solutions?

like image 988
gngrwzrd Avatar asked May 28 '12 21:05

gngrwzrd


2 Answers

There is unfortunately no standard way of doing this. By setting the target OS to a lower number than the base SDK, Xcode will weakly link the libraries and frameworks. When doing that Xcode will not warn you for using methods that may not be available on the target OS.

You could temporarily set the base SDK lower, but that might not always work. Since you want to ignore most of the errors and warnings produced (because they are only called conditionally in your code path), and many warnings and errors are dependant on other error that you may need to resolve before the compiler will give any meaningful output.

I do not think there exist any static analysis tools for this, neither from Apple nor third party.

like image 102
Svein Halvor Halvorsen Avatar answered Nov 16 '22 01:11

Svein Halvor Halvorsen


After doing some research, reading the Apple Doc about it, and trying a number of things. The solution is downloading an old Xcode DMG from Apple, grab the .pkg file for the same SDK as your deployment target and install it in your version of Xcode. Here's how:

  1. Download older Xcode.dmg from Apple
  2. Open the DMG
  3. In Terminal, go into packages: "cd /Volumes/[DMG]/Packages; open ."
  4. Find the SDK you want, something like iPhoneSDK_4.0.pkg
  5. Install that package, but change the install directory to /Applications/Xcode/Contents/Developer
  6. Restart Xcode if it was open.

Now that you have the same SDK as your deployment target, set your BaseSDK to the same. When you build you'll get warnings about missing methods. Your project may or may not successfully build with an older BaseSDK in a new version of Xcode, but that doesn't matter - you've just found the method calls you need to wrap in a feature check with respondsToSelector:.

like image 25
gngrwzrd Avatar answered Nov 16 '22 01:11

gngrwzrd