【问题标题】:Receiver type ‘X’ for instance message is a forward declaration CGPOINT, IOS接收器类型“X”例如消息是前向声明 CGPOINT、IOS
【发布时间】:2012-11-07 14:51:27
【问题描述】:

我看到了同样错误的类似问题。在将代码重构为 Arc 后,我得到 Receiver type ‘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

我该如何解决上述问题?

【问题讨论】:

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


    【解决方案1】:

    您应该在CCParallaxNode-Extras.m 中包含#import "CCParallaxNode.h",但根据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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多