objective-ccgcontextref

Incompatible pointer types initializing 'CGContextRef *'


Not gonna lie, I'm trying to follow a tutorial in a book and I can't get past this warning.

Incompatible pointer types initializing 'CGContextRef *' (aka 'struct CGContext **') with an expression of type 'CGContextRef' (aka 'struct CGContext *')

The offending line is: CGContextRef *imageContext = UIGraphicsGetCurrentContext();

- (IBAction)hide:(id)sender {
    CGContextRef *imageContext = UIGraphicsGetCurrentContext();
    if (_myIcon.alpha == 1) {
        [UIView beginAnimations:nil context:imageContext];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        [UIView setAnimationDuration:3];
        [UIView setAnimationDelegate:self];
        _myIcon.alpha = 0.0;
        [_hideButton setTitle:@"Show" forState:UIControlStateNormal];
    } else if (_myIcon.alpha == 0.0) {
        [UIView beginAnimations:nil context:imageContext];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        [UIView setAnimationDuration:3];
        [UIView setAnimationDelegate:self];
        _myIcon.alpha = 1;
        [_hideButton setTitle:@"Hide" forState:UIControlStateNormal];
    }

    [UIView commitAnimations];

}

Solution

  • CGContextRef is not a class. You don't need the pointer. Change this:

    CGContextRef *imageContext = UIGraphicsGetCurrentContext();
    

    to:

    CGContextRef imageContext = UIGraphicsGetCurrentContext();
    

    Look at the docs for the UIGraphicsGetCurrentContext function. The return type is CGContextRef, not CGContextRef *.