2014-05-14 44 views
0

我在使用Apportable移植到Android的Cocos2d-Iphone應用程序中使用了幾個NS_ENUM。該應用程序在Xcode中完美工作,但在使用Apportable構建時,我得到了NS_ENUM的幾個錯誤。下面是一些錯誤的:使用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 
}; 

我還定義了我的其他枚舉的以類似的方式。

+0

如果您在xcode中啓用推薦的編譯器警告,您將得到相同的錯誤。只需轉換值,並使用0或更好的實際枚舉名稱,而不是NULL(爲指針類型保留)。例如:type =(ballTypes)redBall。 – LearnCocos2D

回答

0

NULL的定義,像這樣:

#define NULL 0 

因此你要分配INT 0到枚舉值。使用= redBall代替= NULL將解決警告。

相關問題