2

I'm moving from iOS6 to iOS7, but I want to keep the code that works for iOS6, so my code looks like this:

if (isiOS7orAbove) {
    sizeios7 = [text boundingRectWithSize:CGSizeMake(TEXTVIEW_WIDTH, 9999)
                options:NSStringDrawingUsesLineFragmentOrigin 
                attributes:nil context:nil];
}else{
    size = [text sizeWithFont:[self cellFont]
            constrainedToSize:CGSizeMake(TEXTVIEW_WIDTH, 9999)
            lineBreakMode:NSLineBreakByWordWrapping];
}

But Xcode keeps warning me that [text sizeWithFont...] is deprecated. Now since I'm sure that my flag isiOS7orAbove can handle the iOS version so I don't need the warning because I have dealt with it.

I don't want to really DISABLE warnings about deprecated methods, what I want is tell Xcode I have deal with it, should work for lower version of iOS.

So is it possible to only remove the warning for [text sizeWithFont...]?

I guess something called a macro should do it, like #IF IOS6 but I don't know exactly how.

Johan
  • 74,508
  • 24
  • 191
  • 319
JimZ
  • 1,182
  • 1
  • 13
  • 30
  • BTW - Is your Deployment Target set to iOS 6? You should not be getting a deprecation warning if your Deployment Target is set to iOS 6. – rmaddy Oct 11 '13 at 15:14

2 Answers2

5

Theoretically, you can suppress diagnostics for a piece of code with #pragma clang diagnostic directive. I never tried it myself, though.

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
size = [text sizeWithFont:...
#pragma clang diagnostic pop
Kreiri
  • 7,840
  • 5
  • 30
  • 36
0

Not really an answer to your question,

but why don't you use

- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options context:(NSStringDrawingContext *)context

(from NSAttributedString)

"Available in iOS 6.0 and later." you just need to convert your NSString to a NSAttributedString just before using it

Jerome Diaz
  • 1,746
  • 8
  • 15