【问题标题】:NS_ENUM errors when building app using Apportable使用 Apportable 构建应用程序时出现 NS_ENUM 错误
【发布时间】:2023-03-19 06:58:01
【问题描述】:

我在我的 Cocos2d-Iphone 应用程序中使用了几个 NS_ENUM,我正在使用 Apportable 将其移植到 Android。该应用程序在 Xcode 中完美运行,但在使用 Apportable 构建时,NS_ENUM 出现了几个错误。以下是一些错误:

/Users/mac/Documents/BallTestApp/BallManager.mm:57:32: error: assigning to 'ballTypes' from incompatible type 'int'
    lastCreatedBallType = NULL;
                        ^ ~~~~
/Users/mac/Documents/BallTestApp/BallManager.mm:382:66: error: cannot initialize a parameter of type 'ballTypes' with an lvalue of type 'int'
                                     withBallType:pBallType atLocation:ballPosition withManager:self];
                                                  ^~~~~~~~~
/Users/mac/Documents/BallTestApp/Ball.h:193:103: note: passing argument to parameter 'myType' here
-(id)initBallWithWorld:(b2World*)world inLayer:(GamePlayLayer*)layer withBallType:(ballTypes)myType atLocation:(CGPoint)myLocation withManager:(BallManager*)myBallManager;
                                                                                             ^
/Users/mac/Documents/BallTestApp/BallManager.mm:575:79: error: cannot initialize a parameter of type 'xBallDistances' with an lvalue of type 'int'
    myBallPos = self.carlBall.position.x  + [self getBallDistance:i];
                                                                  ^

我将 ballTypes 定义为:

typedef NS_ENUM(NSUInteger, ballTypes)  {

redBall = 0, 
yellowBall = 1,
blueBall = 2,
greenBall = 3
};

我也以类似的方式定义了我的其他枚举。

【问题讨论】:

  • 如果您在 xcode 中启用推荐的编译器警告,您将得到相同的错误。只需转换值,并使用 0 或更好的实际枚举名称,而不是 NULL(为指针类型保留)。示例:type = (ballTypes)redBall.

标签: android ios enums cocos2d-iphone apportable


【解决方案1】:

NULL 的定义如下:

 #define NULL 0

因此,您尝试将 int 0 分配给枚举值。

使用= redBall 代替= NULL 将解决警告。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2022-07-04
    • 2019-04-05
    • 2019-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多