Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Use of unresolved identifier 'kCGBlendModeMultiply'

I recently updated to Xcode 7, beta 3.

And I've run into some issues, I can't seem to find any questions for on SO.

When I run my application, i get 3 errors:

Use of unresolved identifier 'kCGBlendModeMultiply'

Use of unresolved identifier 'kCGLineCapRound'

Use of unresolved identifier 'kCGLineJoinMiter'

However the 2 latter ones, disappear, although I assume they will show up after the first one is fixed (hence why I included it in this question).

I didn't see anything in the release notes about these being removed? So I'm a bit stuck at what to do. I tried rewriting the lines of course, but the 3 things I used don't show up as options anymore. In case that they are just gone in the latest Swift 2.0, what can I use instead?

Here's the code for the first error.

    func alpha(value:CGFloat)->UIImage
{
    UIGraphicsBeginImageContextWithOptions(self.size, false, 0.0)
    
    let ctx = UIGraphicsGetCurrentContext()
    let area = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)
    
    CGContextScaleCTM(ctx, 1, -1);
    CGContextTranslateCTM(ctx, 0, -area.size.height)
    CGContextSetBlendMode(ctx, kCGBlendModeMultiply)
    CGContextSetAlpha(ctx, value)
    CGContextDrawImage(ctx, area, self.CGImage)
    
    let newImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    
    return newImage;
}

Here's the code for the 2 latter errors:

for layer in [ self.top, self.middle, self.bottom ] {
        layer.fillColor = nil
        layer.strokeColor = UIColor.whiteColor().CGColor
        layer.lineWidth = 4
        layer.miterLimit = 4
        layer.lineCap = kCALineCapRound
        layer.masksToBounds = true
        
        let strokingPath = CGPathCreateCopyByStrokingPath(layer.path, nil, 4, kCGLineCapRound, kCGLineJoinMiter, 4)
        
        layer.bounds = CGPathGetPathBoundingBox(strokingPath)
        
        layer.actions = [
            "strokeStart": NSNull(),
            "strokeEnd": NSNull(),
            "transform": NSNull()
        ]
        
        self.layer.addSublayer(layer)
    }

Any help would be greatly appreciated! :)

like image 367
MLyck Avatar asked Jul 09 '15 06:07

MLyck


1 Answers

This should work:

CGContextSetBlendMode(ctx, CGBlendMode.Multiply)

... or even just this:

CGContextSetBlendMode(ctx, .Multiply)

If you Ctrl-click on CGContextSetBlendMode and then from its declaration jump (in the same way) to declaration of CGBlendMode then you will see:

enum CGBlendMode : Int32 {

    /* Available in Mac OS X 10.4 & later. */
    case Normal
    case Multiply
    case Screen
    case Overlay

    // ...
}

Similarly, the other line that produces the error should be changed to:

let strokingPath = CGPathCreateCopyByStrokingPath(layer.path, nil, 4, .Round, .Miter, 4)
like image 68
0x416e746f6e Avatar answered Oct 21 '22 05:10

0x416e746f6e