views:

57

answers:

3

I'm taking a hex color value received as a string and converting it to an int so that I can get the proper hex values. I have the following code underneath my imports:

@implementation NSString (HexIntValue)

- (unsigned int)hexIntValue
{

    NSScanner *scanner;
    unsigned int result;

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

    return result;

}

@end

and then the function is called on a string here:

unsigned int x = (int)[globalBGColor hexIntValue];

Everything works fine, but I really want to get rid of the warning because I'm more or less prepared to submit my app.

Thanks!

+3  A: 

The only reason you'd get that error is if you didn't import the header where that is declared. Are you sure you imported the right header? NSString+HexIntValue.h or whatever.

Joshua Weinberg
+1, if the OP were including the header properly, he wouldn't need to cast the return value either.
Carl Norum
Yea, the cast is only necessary here because its assuming a return value of id. You need to make sure that declaration is in scope.
Joshua Weinberg
+3  A: 

I would toss your category in another file. The convention would be to name it "NSSting+HexIntValue.h". Then make sure you #import it. Should clear everything up.

Brad Smith
fantastic. thank you!
culov
A: 

I used to encounter this warnning, you should declare this method in your header file, then import the header file in the .m file.

the .m file don't know the existence of your method.

Tony