I am using a library from this github repo https://github.com/Haneke/HanekeSwift to cache the images that are being downloaded from a server. After updating to swift 2.0 everything is messed up.
I've been able to fix everything but this function:
func hnk_decompressedImage() -> UIImage! {
let originalImageRef = self.CGImage
let originalBitmapInfo = CGImageGetBitmapInfo(originalImageRef)
let alphaInfo = CGImageGetAlphaInfo(originalImageRef)
// See: https://mcmap.net/q/828970/-which-cgimagealphainfo-should-we-use
var bitmapInfo = originalBitmapInfo
switch (alphaInfo) {
case .None:
bitmapInfo &= ~CGBitmapInfo.AlphaInfoMask
bitmapInfo |= CGBitmapInfo(rawValue: CGImageAlphaInfo.NoneSkipFirst.rawValue)
case .PremultipliedFirst, .PremultipliedLast, .NoneSkipFirst, .NoneSkipLast:
break
case .Only, .Last, .First: // Unsupported
return self
}
let colorSpace = CGColorSpaceCreateDeviceRGB()
let pixelSize = CGSizeMake(self.size.width * self.scale, self.size.height * self.scale)
if let context = CGBitmapContextCreate(nil, Int(ceil(pixelSize.width)), Int(ceil(pixelSize.height)), CGImageGetBitsPerComponent(originalImageRef), 0, colorSpace, bitmapInfo) {
let imageRect = CGRectMake(0, 0, pixelSize.width, pixelSize.height)
UIGraphicsPushContext(context)
// Flip coordinate system. See: https://mcmap.net/q/135160/-cgcontextdrawimage-draws-image-upside-down-when-passed-uiimage-cgimage
CGContextTranslateCTM(context, 0, pixelSize.height)
CGContextScaleCTM(context, 1.0, -1.0)
// UIImage and drawInRect takes into account image orientation, unlike CGContextDrawImage.
self.drawInRect(imageRect)
UIGraphicsPopContext()
let decompressedImageRef = CGBitmapContextCreateImage(context)
let scale = UIScreen.mainScreen().scale
let image = UIImage(CGImage: decompressedImageRef, scale:scale, orientation:UIImageOrientation.Up)
return image
} else {
return self
}
}
Specifically this are the lines of code that are throwing the errors:
bitmapInfo &= ~CGBitmapInfo.AlphaInfoMask
bitmapInfo |= CGBitmapInfo(rawValue: CGImageAlphaInfo.NoneSkipFirst.rawValue)
error: Unary operator '~'cannot be applied to operand of type CGBitmapInfo
bitmapInfo |= CGBitmapInfo(rawValue: CGImageAlphaInfo.NoneSkipFirst.rawValue)
error: Binary operator '|=' cannot be applied to an operand of type 'CGBitmapInfo'
if let context = CGBitmapContextCreate(nil, Int(ceil(pixelSize.width)), Int(ceil(pixelSize.height)), CGImageGetBitsPerComponent(originalImageRef), 0, colorSpace, bitmapInfo)
error:Cannot convert value of type 'CGBitmapInfo' to expected argument of type UInt32