views:

260

answers:

4

Hey guys,

Does any one know how to do this?

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

EDIT: 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.

Cheers! Nick.

+2  A: 

From Apple's SFAuthorization.h:

/*!
DEPRECATED: Use obtainWithRight:flags:error:
@method permitWithRight:flags:
@abstract Call permitWithRight to gain a right to have
          access to a privilege operation.
@param rightName The name of an authorization right.
@param flags Authorization flags.
*/
- (OSStatus)permitWithRight:(AuthorizationString)rightName
                      flags:(AuthorizationFlags)flags;

If you're not using an automated documentation builder I'd say something like this is enough:

- (void)doSomething;           /* DEPRECATED */
Georg
Thanks for the comment. If I use the 'permitWithRight' function in SFAuthorization, I get a compiler warning... Is there a way to add a deprecation flag to give compiler warnings?
Nick Cartwright
You could use the preprocessor's command #warning, but it's not standard and likely to not work in all compilers. See http://stackoverflow.com/questions/171435/portability-of-warning-preprocessor-directive
Georg
+4  A: 

Try appending an attribute to your function definition:

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

Taken from here.

Tim
Looks like pretty ugly syntax - but if it works, it works! Thanks Tim.
Nick Cartwright
A: 

You could also follow the HeaderDoc manual. Where this syntax is used:

/*!
 * @abstract Foo is good for bar.
 *
 * @deprecated in version 2.0
 */
PeyloW
+3  A: 

Tim's answer will actually produce a compiler warning; the other versions are merely comments which have no effect w.r.t. the compiler.

If you look at /usr/include/AvailabilityMacros.h, you'll see how Apple does this. That header uses __attribute__((deprecated)) and __attribute__((unavailable)) depending on whether the API is present but deprecated, or has actually been removed from the OS.

Chris Parker