我正在将我的iOS应用转换为64位。我安装了最新的Xcode 5.1(beta 4)。
当我编译应用程序时,我收到了超过100个警告,其中大部分很容易修复。但是,我对以下代码发出警告:
+ (CommentResponseStatus)commentReponseStatusCodeWithStatusString:(NSString *)_status
{
NSArray *commentStatusString = [NSArray arrayWithObjects:@"success", @"needConfirmation", @"stopped", nil];
return [commentStatusString indexOfObject:_status];
}
CommentResponseStatus
声明为:
typedef enum {
success,
needConfirmation,
stopped
} CommentResponseStatus;
我有一个警告“隐式转换失去整数精度:'NSUInteger
'(又名'unsigned long
')到'CommentResponseStatus
'”
警告在return [commentStatusString indexOfObject:_status];
在NSArray
我们有- (NSUInteger)indexOfObject:(id)anObject;
我对此警告感到困惑,现在暂时不知道如何修复它。任何快速帮助将不胜感激。
答案 0 :(得分:17)
根据apple docs约64位更改。
还输入枚举:在LLVM编译器中,枚举类型可以 定义枚举的大小。这意味着一些枚举 类型的大小也可能比您预期的大。该 与所有其他情况一样,解决方案是不做任何关于a的假设 数据类型的大小。而是将任何枚举值分配给变量 使用适当的数据类型
要解决此问题,使用类型创建枚举,如下面的语法。
typedef NS_ENUM(NSUInteger, CommentResponseStatus) {
success,
needConfirmation,
stopped
};
或
typedef enum CommentResponseStatus : NSUInteger {
success,
needConfirmation,
stopped
} CommentResponseStatus;