I am getting a warning in Xcode:
Format specifies type 'int' but the argument has type 'UIViewContentMode'
I have a method that I am using to resize an UIImage
as follows:
- (UIImage *)resizedImageWithContentMode:(UIViewContentMode)contentMode
bounds:(CGSize)bounds
interpolationQuality:(CGInterpolationQuality)quality {
CGFloat horizontalRatio = bounds.width / self.size.width;
CGFloat verticalRatio = bounds.height / self.size.height;
CGFloat ratio;
switch (contentMode) {
case UIViewContentModeScaleAspectFill:
ratio = MAX(horizontalRatio, verticalRatio);
break;
case UIViewContentModeScaleAspectFit:
ratio = MIN(horizontalRatio, verticalRatio);
break;
default:
[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", contentMode];
}
...
UIViewContentMode
seems to reference an Integer so I am not sure on this warning:
typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, ...
How can I get rid of this warning it seems to be incorrect? Is the NSLog
in the exception correct?
You can cast the NSInteger
UIViewContentMode
to an int
like this:
[NSException raise:NSInvalidArgumentException format:@"Unsupported content mode: %d", (int)contentMode];