Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I flag a function as being deprecated in an iOS Objective-C header file?

How do I flag a function as being deprecated in an iOS Objective-C header file?

I'm guessing there's just some keyword I can stick after the function somewhere?

I would like for a compiler warning to be generated should anyone try and use the deprecated function, similar to the behavior seen in Apple's APIs.

like image 625
Nick Cartwright Avatar asked Sep 18 '09 10:09

Nick Cartwright


2 Answers

Try appending an attribute to your method declaration:

- (void)fooBar __attribute__ ((deprecated));

Taken from here.

like image 190
Tim Avatar answered Sep 28 '22 23:09

Tim


Instead of __attribute__((deprecated)), you can use use the macros defined in <cdefs.h>:

- (void)fooBar __deprecated; // Or better: - (void)fooBar __deprecated_msg("Use barFoo instead."); 

Or you can use the macros defined in <AvailabilityMacros.h>:

- (void)fooBar DEPRECATED_ATTRIBUTE; // Or better: - (void)fooBar DEPRECATED_MSG_ATTRIBUTE("Use barFoo instead."); 

If you use Objective-C, it makes no difference as you are going to use a modern compiler, so you can go for Apple short syntax __deprecated_msg(). But if you use C for cross-platform, then DEPRECATED_MSG_ATTRIBUTE() uses the optimal availability definitions (for instance, it supports GCC3.1).

like image 44
Cœur Avatar answered Sep 29 '22 00:09

Cœur