Reputation: 273
How can I set a variable to a CGMakePoint
?
I've tried setting and calling the variable in the following ways:
I expected this one to work.
float p0[] = {0, 100};
UIBezierPath *point = [[UIBezierPath alloc] init];
[point moveToPoint:CGPointMake(p0)]; // this tells me I need two arguments
Nope!
float *p0 = CGPointMake(0, 100);
UIBezierPath *point = [[UIBezierPath alloc] init];
[point moveToPoint:p0];
Failed!
NSObject *p0 = CGPointMake(0, 100);
UIBezierPath *point = [[UIBezierPath alloc] init];
[point moveToPoint:p0];
Another error!
id p0 = CGPointMake(0, 100);
UIBezierPath *point = [[UIBezierPath alloc] init];
[point moveToPoint:p0];
Par for the course!
NSString *p0 = @"CGPointMake(0, 100)";
UIBezierPath *point = [[UIBezierPath alloc] init];
[point moveToPoint:p0];
I'm guessing I am just casting it as the wrong type. I don't necessarily need to set my variable = CGPointMake(0, 100)
but I do need to be able to set my variable to my coordinates = (0, 100)
.
Upvotes: 1
Views: 3902
Reputation: 9902
CGPoint myPoint = CGPointMake(10.0, 50.0);
But please, do yourself a favor and learn properly what you're doing. The problem you're facing is extremely basic, and if you're stuck at this level, there will be insurmountable problems soon.
I usually recommend the Big Nerd Ranch Guide books for beginners, but I'm not 100% sure if they start on a basic enough level for you.
This is not meant as an insult; merely as a friendly hint.
Upvotes: 9
Reputation: 273
I was right... I was casing my variable as the wrong type. Once I set it to CGPoint
it worked as expected.
CGPoint p0 = CGPointMake(0, 100);
UIBezierPath *point = [[UIBezierPath alloc] init];
[point moveToPoint:p0];
Upvotes: -1