warning on typedef enum when converting app to 64-bit
我正在将iOS应用程序转换为64位。我安装了最新的Xcode5.1(测试版4)。
当我编译这个应用程序时,我收到了100多个警告,其中大多数都很容易修复。但是,我对以下代码有一个警告:
1 2 3 4 5 6 | + (CommentResponseStatus)commentReponseStatusCodeWithStatusString:(NSString *)_status { NSArray *commentStatusString = [NSArray arrayWithObjects:@"success", @"needConfirmation", @"stopped", nil]; return [commentStatusString indexOfObject:_status]; } |
其中
1 2 3 4 5 | typedef enum { success, needConfirmation, stopped } CommentResponseStatus; |
我有一个警告:"隐式转换会丢失整数精度:"
警告在
在
我对这个警告感到困惑,目前还不知道如何解决它。任何快速的帮助都将不胜感激。
根据苹果文档,大约64位的变化。
Enumerations Are Also Typed : In the LLVM compiler, enumerated types can
define the size of the enumeration. This means that some enumerated
types may also have a size that is larger than you expect. The
solution, as in all the other cases, is to make no assumptions about a
data type’s size. Instead, assign any enumerated values to a variable
with the proper data type
要解决此问题,请使用以下语法类型创建枚举。
1 2 3 4 5 | typedef NS_ENUM(NSUInteger, CommentResponseStatus) { success, needConfirmation, stopped }; |
或
1 2 3 4 5 | typedef enum CommentResponseStatus : NSUInteger { success, needConfirmation, stopped } CommentResponseStatus; |