我在这里犯了什么愚蠢的noob错误?

Con*_*oob 2 iphone xcode objective-c

我有一个方法:

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

    return CGPointMake(xDif, yDif);
}
Run Code Online (Sandbox Code Playgroud)

我尝试按如下方式调用它:

- (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);
}
Run Code Online (Sandbox Code Playgroud)

但我得到一个编译错误,我尝试使用该方法:"无效的初始化程序".

我究竟做错了什么?

Wev*_*vah 5

calculateVectorBetweenThisPoint:andThisPoint:宣布之后再使用?如果不是,编译器将假定一个返回类型,id它绝对是一个无效的东西CGPoint.

  • @ConfusedNoob:为私有方法使用类扩展:http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCategories.html#//apple_ref/doc/uid/TP30001163-CH20 -SW2 (2认同)