gpt4 book ai didi

objective-c - 接收者类型 ‘X’ 例如消息是前向声明 CGPOINT, IOS

转载 作者:行者123 更新时间:2023-12-01 17:26:52 26 4
gpt4 key购买 nike

对于相同的错误,我看到了类似的问题。将代码重构为 Arc 后,我得到了 Receiver type ‘CGPointObject’ for instance message is a forward declaration 错误。并且建议将@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

如何解决上述问题?

最佳答案

你在 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

关于objective-c - 接收者类型 ‘X’ 例如消息是前向声明 CGPOINT, IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13457937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com