Aug 27 2010

Disable deprecated warnings with GCC

Recently I wrote some conditional code to call various methods depending on the version of iOS running on the device. A problem I came across was that because I still called some deprecated methods I was getting warnings during my build. As I treat all warnings as errors I had to find a solution which would compile. #pragma was the answer.

You can use the following line to disable warnings for depreciated calls:

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

And use this to re-enable it:

#pragma GCC diagnostic warning "-Wdeprecated-declarations"

Here’s how I used it:

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
  if([super respondsToSelector:@selector(initWithStyle:reuseIdentifier:)])
  {
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
      [self setupCell];
    }
  }
  else
  {
    if(self = [super initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier])
    {
      [self setupCell];
    }
  }
  return self;
}
#pragma GCC diagnostic warning "-Wdeprecated-declarations"