Jayaprada
Jayaprada

Reputation: 954

Suppress `deprecated` warnings in Xcode

dismissModalViewControllerAnimated is deprecated:first deprecated in iOS 6.0

Upvotes: 7

Views: 9662

Answers (4)

Schrodingrrr
Schrodingrrr

Reputation: 4271

If I am correct, you simply want to suppress the warnings.

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

This is simply to suppress the warnings. In release builds, you should not use any deprecated functions.

EDIT: To suppress specific code that invokes warnings, use :

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

    [self dismissModalViewControllerAnimated:YES];

#pragma clang diagnostic pop

Upvotes: 33

neoscribe
neoscribe

Reputation: 2421

@n00bProgrammer thanks for your answer.

For those of us who still have code that supports earlier versions of iOS, the way I handle such old code is to wrap the older code in a version macro test as well as to suppress the compiler warnings that result.

Note that sometimes a deprecated item generates an implicit conversion warning that needs to be suppressed using "-Wconversion".

    if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
        #pragma clang diagnostic push
        #pragma clang diagnostic ignored "-Wdeprecated-declarations"
        #pragma clang diagnostic ignored "-Wconversion"
        [controlCenter.label setLineBreakMode:UILineBreakModeWordWrap];
        #pragma clang diagnostic pop
    } else {
        [controlCenter.label setLineBreakMode:NSLineBreakByWordWrapping];
    }

You can find the version checker for older Objective-C code here: SYSTEM_VERSION_LESS_THAN()

You can find the version checker for new Swift and Objective-C code here: Swift and Objective-C version check past iOS 8

Upvotes: 2

Prabhu Natarajan
Prabhu Natarajan

Reputation: 869

use thus the following code it works perfect

[self dismissViewControllerAnimated:YES completion:nil];

Tested and working fine.

:)

Upvotes: 0

Anbu.Karthik
Anbu.Karthik

Reputation: 82759

use

[self presentViewController:loginController animated:YES completion:nil];

or

[self presentModalViewController:loginController animated:YES];

or

[self dismissViewControllerAnimated:NO completion:nil];

Upvotes: 1

Related Questions