2012-11-19 59 views
1

我也看到過類似的問題,對於同樣的錯誤。重構代碼到Arc後,我得到接收器類型'CGPointObject'對於消息實例是前向聲明錯誤。並建議將move @class方法移至聲明的.h文件和#import .h文件,並明智地使用{。接收器類型'X'的實例消息是一個前向聲明CGPOINT,IOS

我做了所有的建議,但我仍然得到錯誤。

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 

如何解決上述問題?

回答

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 
+0

非常感謝,行之有效。 –

+0

這是一個正確答案的隨機downvote。 – Joe

相關問題