OGeek|极客世界-中国程序员成长平台

标题: iphone - 仅在为设备编译时变量 "undeclared" [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:18
标题: iphone - 仅在为设备编译时变量 "undeclared"

我收到未声明的错误“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) initWithActivationTimefloat)time;

- (int) updateWithDeltafloat)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) initWithImageImage *)aGraphic andPositionVector2f)aPosition;

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

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

@end

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

#import "layer.h"
#import "AIEngine.h"

@implementation Player

@synthesize position;

- (id) initWithImageImage *)aGraphic andPositionVector2f)aPosition {

    self = [super init];

    if(self) {

        playerGraphic = [aGraphic retain];
        position = aPosition;


    }

    return self;
}

- (int) deployWithSceneMainScene *)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 并且没有抛出错误。我想找出问题的根源,而不仅仅是使用其他编译器。有什么想法吗?



Best Answer-推荐答案


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

我会尝试这两件事:

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

currentUpdateMethod = @selector(updateInactiveState);

[self setCurrentUpdateMethodselector(updateInactiveState)];

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

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

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

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4