0

In my code I use

[[self presentingViewController] dismissViewControllerAnimated:YES
                                                    completion:dismissBlock];

The thing is my deployment target is set to: 5.0.

While base SDK is 6.1.

Was I not supposed to get a warning by XCode? (because I think the above method got introduced in iOS6).

Mat
  • 202,337
  • 40
  • 393
  • 406
  • 1
    No, it won't warn you about things available in the base SDK. See [this answer](http://stackoverflow.com/a/6813110/264775). – thegrinner Aug 15 '13 at 12:30

3 Answers3

3

Unfortunately no, Xcode doesn't check if you use symbols that are not available in your deployment SDK.
It only checks your code against the base SDK.

But you can use some third-party software for this, like DeployMate.

That being said, as others pointed it out, dismissViewControllerAnimated:completion: is available since iOS 5, so your code is safe.

But it's always a good idea to check for unavailable or deprecated APIs in your app, using something like DeployMate.

EDIT

Here's an answer to your comment:

If you deployment target is 5.0 and your base SDK 6.0, using a symbol available in the 6.0 SDK on an iOS 5 device will crash the application.
But Xcode won't warn about this when compiling, hence the need of some third-party software.

Once you identified the problematic symbol, using respondsToSelector: is the way to go, as it's better than simple version checking.

This way, you can have conditional code that will run with both SDK versions:

if( [ someObject respondsToSelector: @selector( someIOS6Method ) ] )
{ /* iOS 6 code */ }
else
{ /* iOS 5 code */ }

Only do this if you have detected SDK issues. Don't do this for everything.

Macmade
  • 52,708
  • 13
  • 106
  • 123
  • I believe tool Analyse checks that, doesn't it? – CainaSouza Aug 15 '13 at 12:38
  • 1
    @CainaSouza Unfortunately it doesn't. That's «only» static code analysis, with Clang. – Macmade Aug 15 '13 at 12:40
  • @Macmade: dear Macmade, I also know such thing, if my base SDK is 6 and I use in code some method which if from iOS6 and user runs the app from iOS5 - this may result in problem right? I know one of the solution is to use `respondsToSelector` but my question is against which methods should I use respondsToSelector? Shall I apply it to all methods? –  Aug 15 '13 at 12:42
  • @Macmade: Thanks, yes that was my concern, when to use `respondsToSelector`? Doing it with each method call did not seem a good idea to me ?? –  Aug 15 '13 at 12:53
  • @user2685008 Only do this if you identified an issue, or if you need to detect specific device features. – Macmade Aug 15 '13 at 12:55
  • @Macmade: For example, if I use some method, in which doc says it is available from iOS6 right? –  Aug 15 '13 at 12:57
  • @user2685008 Yes... But give DeployMate a try. Saves you from reading each method's doc... – Macmade Aug 15 '13 at 13:02
  • Also, you can currently download the iOS simulator version back to 5.0. If you run the app on the iOS 5 simulator and it crashes, you have a problem. – Marcus Adams Aug 15 '13 at 13:49
1

According to UIVIewController class reference, this method is available from iOS 5.0 and higher.

Availability
Available in iOS 5.0 and later.
CainaSouza
  • 1,417
  • 2
  • 16
  • 31
  • I think you are right, in the doc it said "dismissModalViewControllerAnimated" was deprecated, and said to use above method... I thought for a moment it got introduced in iOS6 –  Aug 15 '13 at 12:34
0

It is not ok to warn you. It doesn't have this warnining included in the default bundle of the SDK.

BVdjV
  • 116
  • 1
  • 1
  • 11