iphone - 仅在为设备编译时变量 "undeclared"
<p><p>我收到未声明的错误“currentUpdateMethod”(在此函数中首次使用)。 this 引用的变量 currentUpdateMethod 是在头文件中声明的 SEL 类型的实例变量。因为构建到模拟器并运行应用程序按预期工作,我相信我已经正确设置了一切。这个错误今天才出现 - 我已经在设备上测试了几天,没有问题。我确实尝试清理和清理所有目标。我什至在 xcode 中将变量名输入到文件中,它会为我自动完成变量。什么可能导致设备在这些变量上编译失败,而不是模拟器编译失败?</p>
<p>编辑:代码如下。</p>
<p>父类(super class):</p>
<pre><code>#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
</code></pre>
<p>然后是问题类:</p>
<pre><code>#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
</code></pre>
<p>及其实现,抛出错误的地方:</p>
<pre><code>#import "Player.h"
#import "AIEngine.h"
@implementation Player
@synthesize position;
- (id) initWithImage:(Image *)aGraphic andPosition:(Vector2f)aPosition {
self = ;
if(self) {
playerGraphic = ;
position = aPosition;
}
return self;
}
- (int) deployWithScene:(MainScene *)newScene {
;
;
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
</code></pre>
<p>重申一下,这六个错误<em>仅</em>在为设备构建时抛出。当我为模拟器构建时,应用程序构建并正常运行。</p>
<p>Edit2:我只切换到 LLVM 并且没有抛出错误。我想找出问题的根源,而不仅仅是使用其他编译器。有什么想法吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我很确定这是 Xcode 中的一个错误,因为我可以看到您的代码没有任何问题。</p>
<p>我会尝试这两件事:</p>
<p>1) 为了快速修复,您可以尝试综合变量然后替换</p>
<pre><code>currentUpdateMethod = @selector(updateInactiveState);
</code></pre>
<p>与</p>
<pre><code>;
</code></pre>
<p>2) 从项目中删除文件。从头开始重新创建类。将旧代码复制到新文件中。 </p>
<p>看起来这个人也有类似的问题:<a href="https://stackoverflow.com/questions/5977005/strange-error-regarding-instance-variables-superclass" rel="noreferrer noopener nofollow">Strange error regarding instance variables & superclass</a> </p>
<p>如果这些建议有帮助,请告诉我。如果他们这样做,我会请您将错误提交给 Xcode 开发人员:)</p></p>
<p style="font-size: 20px;">关于iphone - 仅在为设备编译时变量"undeclared",我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/6119835/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/6119835/
</a>
</p>
页:
[1]