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

Mor*_*ang 1 objective-c cocos2d-iphone ios automatic-ref-counting

我已经看到了相同错误的类似问题.在将代码重构为Arc之后,我得到 Receiver类型'CGPointObject'作为实例消息是一个前向声明错误.建议将@class方法移动到.h文件和#import .h文件的声明,并明智地使用{.

我做了所有的建议,但我仍然得到错误.

CCParallaxNode-Extras.h

#import "cocos2d.h"

@class CGPointObject;

@interface CCParallaxNode (Extras)

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

@end
Run Code Online (Sandbox Code Playgroud)

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

课程定义: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
Run Code Online (Sandbox Code Playgroud)

我该如何解决上述问题?

Joe*_*Joe 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
Run Code Online (Sandbox Code Playgroud)