문제

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).

도움이 되었습니까?

해결책 2

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];

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top