views:

118

answers:

1

I have a method:

- (CGPoint) calculateVectorBetweenThisPoint:(CGPoint)firstPoint andThisPoint:(CGPoint)secondPoint
{
    float xDif = firstPoint.x - secondPoint.x;
    float yDif = firstPoint.y - secondPoint.y;

    return CGPointMake(xDif, yDif);
}

And I try to invoke it as follows:

- (float) angleBetweenThisPoint:(CGPoint)firstPoint andThisPoint:(CGPoint)secondPoint
{
// COMPILE ERROR HERE: Invalid Initializer 
    CGPoint vector = [self calculateVectorBetweenThisPoint:firstPoint andThisPoint:secondPoint];

    return atan2(vector.x, vector.y);
}

But I get a compilation erorr where I try to use the method: "Invalid Initializer".

What am I doing wrong?

+5  A: 

Is calculateVectorBetweenThisPoint:andThisPoint: declared before you use it? If it's not, the compiler will assume a return type of id which is definitely an invalid thing to put into a CGPoint.

Wevah
Correct. `calculateVectorBetweenThisPoint:andThisPoint:` must either be defined in the header file, or be placed before `angleBetweenThisPoint:andThisPoint:` in the implementation file.
Can Berk Güder
+1 (even though you mean declared, not defined.)
Nikolai Ruhe
Whoops, you're right. Editing!
Wevah
Nice. I didn't want to declare as it's basically a 'private' method (right?). But putting it up top works nicely.
ConfusedNoob
@ConfusedNoob: Use a class extension for private methods: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCategories.html#//apple_ref/doc/uid/TP30001163-CH20-SW2
Nikolai Ruhe
Was just about to suggest that (+1).
Wevah