Initializing 'CGRect' incompatible expression


I’m in the middle of chapter 6 this is my code:

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect bounds = [self bounds];

CGPoint center;
center.x = bounds.origin.x + bounds.size.width / 2.0;
center.y = bounds.origin.y + bounds.size.height / 2.0;

float maxRadius = hypot(bounds.size.width, bounds.size.height) / 4.0;

CGContextSetRGBStrokeColor(ctx, 0.6, 0.6, 0.6, 1.0);

CGContextSetLineWidth(ctx, 10);

CGContextAddArc(ctx, center.x, center.y, maxRadius, 0.0, M_PI * 2.0, YES);



in the " CGRect bounds = [self bounds];" line I’m receiving a semantic issue: “Initializing ‘CGRect’ (aka ‘struct CGRect’ with an expression of incompatible type ‘UIView’”

I do not what to do. I can not compile.


Your code is as good as gold.

Are you sure you have posted the code that you can’t compile?

You are probably doing this:

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGRect bounds = self;


This is exactly what I got.

I really don’t know what to do. That’s the same code I just copy/paste


The code snipet you’ve sent looks OK, but could you have another instance of ‘bounds’ already defined?
Try replacing your bounds with bounds2 and see what happens…


Actually ignore that, I just read the message properly…
The problem (I suspect) is that you have nice code, but it’s in the wrong class.
My guess (from the surrounding methods) is that you have added the code to your AppDelegate.M
Instead of your view.m class…
And because you are using SELF bounds - the self is not a view, so it has no bounds!

Go back and check the instructions for the class that you are adding.

…and another hint that things are going wrong will be that code completion is not working.
If you tried to retype the line and got as far as “[self b” and was not suggesting a valid completion that should be the first hint.


Wrong class declaration :open_mouth: , everything is great and running now.

Thanks for your help :smiley: :smiley:


You’re welcome! Gosh those compiler messages can be cryptic, but the best is yet to come!