XCode: missing „deprecated“ warnings

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

Compiler setting: Warn about deprecated calls

But be careful, this complains e.g. here only once while initWithFrame: 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).

Flattr this!

Post a Comment

Your email is never published nor shared. Required fields are marked *