Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly deprecate a method in Xcode 4

I've just looked over the answers here but didn't help. When I add a deprecated attribute only to method declaration than the compiler says Attributes on method implementation and its declaration must match. Do I need to add smth to method implementation?

Thanks!

like image 482
Borut Tomazin Avatar asked Apr 11 '12 05:04

Borut Tomazin


1 Answers

Just add the attribute to the declaration:

@interface Blah
- (void)method __attribute__((deprecated));
@end

Provided your includes are correct for the translation, this should work fine. Perhaps you have added the attribute to the definition, not the declaration? Otherwise, a demonstration (code sample) would help.

Update

Although the above approach works for typical messages, it appears clang gets confused with IBActions.

With clang, ibaction attributes are implicitly inserted (for what was formerly a typedef).

When the attribute is specified in the declaration only, the preprocessor output is as follows:

// preprocessed declaration
- (void)__attribute__((ibaction))setSomething:(id)sender __attribute__((noreturn));
// preprocessed implementation
- (void)__attribute__((ibaction))setSomething:(id)sender
...    

So, it appears the compiler is just confused by this hidden decoration, and you must also add the attribute to the implementation/definition to suppress the warning when the method is an IBAction.

like image 54
justin Avatar answered Nov 15 '22 06:11

justin