【发布时间】:2011-05-25 05:15:55
【问题描述】:
我收到未声明的错误“currentUpdateMethod”(在此函数中首次使用)。 this 引用的变量 currentUpdateMethod 是在头文件中声明的 SEL 类型的实例变量。因为构建到模拟器并运行应用程序按预期工作,我相信我已经正确设置了一切。这个错误今天才出现 - 我已经在设备上测试了几天,没有问题。我确实尝试清理和清理所有目标。我什至在 xcode 中将变量名输入到文件中,它会为我自动完成变量。什么可能导致设备在这些变量上编译失败,而不是模拟器编译失败?
编辑:代码如下。
超类:
#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 并且没有抛出错误。我想找出问题的根源,而不仅仅是使用其他编译器。有什么想法吗?
【问题讨论】:
-
你能给我们看看代码吗?您可能在某处有一些
#ifdef宏可能会搞砸。 -
@BoltClock 你真的认为他会知道如何放置这样的宏 - 但没有意识到这是导致问题的原因?但我确实同意,没有代码,我们无能为力...
-
您使用的是 GCC 还是 LLVM? GCC 有一些...与“受保护”变量相关的有趣错误(请参阅stackoverflow.com/questions/2778405/…)
-
如果不是 LLVM,我会尝试切换编译器。奇怪的是它一次编译没有错误,而且最近才开始。
标签: iphone objective-c ios compilation device