'NSString'可能无法响应'-hexIntValue'警告,功能正常

D-N*_*ice 2 iphone objective-c iphone-sdk-3.0

我将接收的十六进制颜色值作为字符串并将其转换为int,以便我可以获得正确的十六进制值.我的导入下面有以下代码:

@implementation NSString (HexIntValue)

- (unsigned int)hexIntValue
{

    NSScanner *scanner;
    unsigned int result;

    scanner = [NSScanner scannerWithString: self];  
    [scanner scanHexInt: &result];

    return result;

}

@end
Run Code Online (Sandbox Code Playgroud)

然后在这里调用函数:

unsigned int x = (int)[globalBGColor hexIntValue];
Run Code Online (Sandbox Code Playgroud)

一切正常,但我真的想摆脱警告,因为我或多或少准备提交我的应用程序.

谢谢!

Bra*_*Guy 5

我会把你的类别扔到另一个文件中.惯例是将其命名为"NSSting + HexIntValue.h".然后确保#import它.应该清除一切.