2010-06-22-xcode-missing-deprecated-warnings.md 3.4 KB


title: 'XCode: missing „deprecated“ warnings' author: Marcus Rohrmoser type: post date: 2010-06-22T10:55:56+00:00 url: /2010/06/xcode-missing-deprecated-warnings/ yourls_shorturl:

categories:

  • en
    • development tags:
    • alloc
    • compiler
    • deprecated
    • gcc
    • initWithFrame
    • iPhone
    • Objective C
    • UITableViewCell
    • warning
    • XCode

when developing for long-term use, you want to use APIs that aren't likely to be removed soon, a.k.a. „deprecated“.

So, don't use downward compatible calls below a point you really aim for.

XCode helps with compiler warnings about „deprecated“ calls – if „Project -> Edit Project Settings -> GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS“ is set:

Compiler setting: Warn about deprecated calls

But be careful, this complains e.g. here only once while <a href="http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableViewCell_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/doc/uid/TP40006938-CH3-SW32">initWithFrame:</a> is also deprecated (compiling for iPhone OS 3.0):

No "deprecated" warning on initXY

As Kevin Ballard pointed out at Stackoverflow, this is because [AnyClass alloc] returns a type id – which doesn't know about it's interface.

To get this kind of compiler warnings, you have to type-cast the [AnyClass alloc] like this:

[(AnyClass*)[AnyClass alloc] initXY];

Maybe time for a macro?

The macro could look like

// http://blog.mro.name/2010/06/xcode-missing-deprecated-warnings/
#define alloc(c)    ((c*)[c alloc])

Migrate your codebase via XCode „Edit -> Find in Project“ with search pattern \[\s*([^\[\]]+)\s+alloc\s*\] and replacement pattern alloc(\1).