Reputation: 1553
I have seen similar questions for same error.After refactoring code to Arc I get Receiver type ‘CGPointObject’ for instance message is a forward declaration error . And it is recommended that move @class method to .h file and #import .h file of declaration, and use { wisely.
I did all of recommendations but I still get error.
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
Definition of class: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
How can I solve above problem ?
Upvotes: 2
Views: 7425
Reputation: 57179
You include #import "CCParallaxNode.h"
in CCParallaxNode-Extras.m
like you should but according to CCParallaxNode.m
you are defining both the @interface
and the @implementation
. You need to move the @interface
section out of CCParallaxNode.m
and into the header file.
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
Upvotes: 9