gpt4 book ai didi

iphone - 仅在为设备编译时变量 "undeclared"

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:52:03 28 4
gpt4 key购买 nike

我收到错误“currentUpdateMethod”未声明(首次在此函数中使用)。 this 引用的变量 currentUpdateMethod 是在头文件中声明的 SEL 类型的实例变量。因为构建到模拟器并运行应用程序按预期工作,我相信我已经正确设置了所有内容。这个错误今天才出现——我已经在设备上测试了几天没有问题。我确实尝试清理并清理所有目标。我什至在 xcode 的文件中输入变量名,它会自动为我完成变量。什么会导致设备编译在这些变量上失败而不是模拟器编译?

编辑:代码如下。

父类(super class):

#import "Deployable.h"

@interface Drawable : Deployable {

float currentDelta;

SEL currentUpdateMethod;
SEL currentAnimationMethod;
SEL currentBatchMethod;

float rotation;
}

- (id) init;

- (id) initWithActivationTime:(float)time;

- (int) updateWithDelta:(float)delta;

- (int) animate;

- (int) batch;

@end

然后是问题类:

#import "Drawable.h"
#import "Structures.h" //contains Vector2f declaration

@interface Player : Drawable {

Image *playerGraphic;

Vector2f position;

}

@property (nonatomic) Vector2f position;

- (id) initWithImage:(Image *)aGraphic andPosition:(Vector2f)aPosition;

- (void) setupInactiveState;
- (int) updateInactiveState;
- (int) animateInactiveState;
- (int) batchInactiveState;

- (void) setupActiveState;
- (int) updateActiveState;
- (int) animateActiveState;
- (int) batchActiveState;

@end

及其实现,抛出错误的地方:

#import "Player.h"
#import "AIEngine.h"

@implementation Player

@synthesize position;

- (id) initWithImage:(Image *)aGraphic andPosition:(Vector2f)aPosition {

self = [super init];

if(self) {

playerGraphic = [aGraphic retain];
position = aPosition;


}

return self;
}

- (int) deployWithScene:(MainScene *)newScene {

[super deployWithScene:newScene];

[self setupInactiveState];

return 1;
}

- (void) setupInactiveState {

currentUpdateMethod = @selector(updateInactiveState); //'currentUpdateMethod' undeclared (first use in this function)
currentAnimationMethod = @selector(animateInactiveState); //'currentAnimateMethod' undeclared (first use in this function)
currentBatchMethod = @selector(batchInactiveState); //'currentAnimateMethod' undeclared (first use in this function)

}

- (void) setupActiveState {

currentUpdateMethod = @selector(updateActiveState); //'currentUpdateMethod' undeclared (first use in this function)
currentAnimationMethod = @selector(animateActiveState); //'currentAnimateMethod' undeclared (first use in this function)
currentBatchMethod = @selector(batchActiveState); //'currentBatchMethod' undeclared (first use in this function)

}

@end

重申一下,这六个错误在为设备构建时抛出。当我为模拟器构建时,应用程序可以正常构建和运行。

Edit2:我只切换到 LLVM 并且没有抛出错误。我想找出问题的根源,而不是仅仅使用其他编译器。有什么想法吗?

最佳答案

我很确定这是 Xcode 中的错误,因为我可以看到您的代码没有任何问题。

我会尝试这两种方法:

1) 为了快速修复,您可以尝试综合变量然后替换

currentUpdateMethod = @selector(updateInactiveState);

[self setCurrentUpdateMethod:@selector(updateInactiveState)];

2) 从项目中删除文件。从头开始重新创建类。将旧代码复制到新文件中。

看起来这个人有类似的问题:Strange error regarding instance variables & superclass

如果这些建议有帮助,请告诉我。如果他们这样做,我会恳请您将错误提交给 Xcode 开发人员 :)

关于iphone - 仅在为设备编译时变量 "undeclared",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6119835/

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