2

I am using this code from a guy

in the middle of this code, we have

- (NSString *)hexStringFromColor {
        return [NSString stringWithFormat:@"%0.6X", self.rgbHex];
}

This was working fine until Xcode 4.4. Now, I see this error: format specifies type unsigned int but the argument has type UInt32 (aka unsigned long).

Why is Xcode complaining in 4.4 but not before? what specifier should I use?

thanks.

4

2 回答 2

2

由于rgbHex似乎是一个无符号长整数,因此正确的格式说明符@"%0.6lX"l代表long.

iOS 字符串格式说明符列表

于 2012-09-14T15:55:01.410 回答
2

Try %0.6lX,其中 'l' 指定后面的 'X' 是 long 而不是 int。ll如果值实际上是 long long,您也可以使用。

在此处输入图像描述

于 2012-09-14T15:53:13.097 回答