接收器类型'X'例如消息是前向声明CGPOINT,IOS

时间:2012-11-19 16:22:10

标签: objective-c ios cocos2d-iphone automatic-ref-counting

我已经看到了相同错误的类似问题。将代码重构为Arc后,我得到接收器类型'CGPointObject'例如消息是前向声明错误。建议将@class方法移动到.h文件和#import .h文件的声明,然后使用{明智。

我做了所有建议,但我仍然遇到错误。

CCParallaxNode-Extras.h

#import "cocos2d.h"

@class CGPointObject;

@interface CCParallaxNode (Extras)

-(void) incrementOffset:(CGPoint)offset forChild:(CCNode*)node;

@end

CCParallaxNode-Extras.m

    #import "CCParallaxNode-Extras.h"
    #import "CCParallaxNode.h"


    @implementation CCParallaxNode(Extras)


    -(void) incrementOffset:(CGPoint)offset forChild:(CCNode*)node 
    {

        for( unsigned int i=0;i < parallaxArray_->num;i++) {
            CGPointObject *point = parallaxArray_->arr[i];
            if( [[point child] isEqual:node] ) {
                [point setOffset:ccpAdd([point offset], offset)];
                break;
            }
        }
    }

@end

课程定义:CCParallaxNode.m

#import "CCParallaxNode.h"
#import "Support/CGPointExtension.h"
#import "Support/ccCArray.h"

@interface CGPointObject : NSObject
{
    CGPoint ratio_;
    CGPoint offset_;
    CCNode *child_; // weak ref
}
@property (nonatomic,readwrite) CGPoint ratio;
@property (nonatomic,readwrite) CGPoint offset;
@property (nonatomic,readwrite,assign) CCNode *child;
+(id) pointWithCGPoint:(CGPoint)point offset:(CGPoint)offset;
-(id) initWithCGPoint:(CGPoint)point offset:(CGPoint)offset;
@end
@implementation CGPointObject
@synthesize ratio = ratio_;
@synthesize offset = offset_;
@synthesize child=child_;

+(id) pointWithCGPoint:(CGPoint)ratio offset:(CGPoint)offset
{
    return [[[self alloc] initWithCGPoint:ratio offset:offset] autorelease];
}
-(id) initWithCGPoint:(CGPoint)ratio offset:(CGPoint)offset
{
    if( (self=[super init])) {
        ratio_ = ratio;
        offset_ = offset;
    }
    return self;
}
@end

如何解决上述问题?

1 个答案:

答案 0 :(得分:8)

您在#import "CCParallaxNode.h"中加入了CCParallaxNode-Extras.m,但是根据CCParallaxNode.m您要定义@interface@implementation。您需要将@interface部分移出CCParallaxNode.m并移至头文件中。

CCParallaxNode.h

//Add necessary includes ...

@interface CGPointObject : NSObject
{
    CGPoint ratio_;
    CGPoint offset_;
    CCNode *child_; // weak ref
}
@property (nonatomic,readwrite) CGPoint ratio;
@property (nonatomic,readwrite) CGPoint offset;
@property (nonatomic,readwrite,assign) CCNode *child;
+(id) pointWithCGPoint:(CGPoint)point offset:(CGPoint)offset;
-(id) initWithCGPoint:(CGPoint)point offset:(CGPoint)offset;
@end