Question

I just updated Xcode from version 4.6.2 to 5.0, and after doing a method in my project (created in Xcode 4.6.2) is suddenly giving a compiler warning. I have tried re-opening the project in both the old and new versions of Xcode, and I have confirmed that the same method gives no warnings in 4.6.2.

Here is the line of code eliciting the warning in Xcode 5.0:

CGContextRef context = CGBitmapContextCreate(NULL, frame.size.width * scaleFactor, frame.size.height * scaleFactor, 8, frame.size.width * scaleFactor * 4, colorSpace, kCGImageAlphaPremultipliedFirst);

And the warning says:

"Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGBitMapInfo' (aka 'enum CGBitMapInfo')"

It does not appear to be a deprecation warning, but I am not quite familiar enough with these classes to interpret the meaning or know how to resolve it. Any help is appreciated.

Was it helpful?

Solution

The kCGImageAlpha* enum values are supposed to fill the first five bits in CGBitmapInfo. However, since the C type system can't express this, you get a warning that the types don't match, even though they were intended to.

The correct solution is to cast your alpha enum value to CGBitmapInfo, since that's what it is:

(CGBitmapInfo)kCGImageAlphaPremultipliedFirst

OTHER TIPS

Saw a comment https://github.com/inkling/Subliminal/issues/23 by aegolden that the intention of the new XCode warning might be directing you to use different masks on these enum types to construct and concatenate various flags. So instead of just using kCGImageAlphaPremultipliedFirst, use

(kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedFirst)

The warning will disappear after this change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top