Format指定类型'unsigned short'但参数的类型为'int'

Sno*_*man 2 xcode objective-c

我有一个扫描字符串的方法,将任何新行转换<br>为HTML.有问题的一行是:

NSCharacterSet *newLineCharacters = [NSCharacterSet characterSetWithCharactersInString:
          [NSString stringWithFormat:@"\n\r%C%C%C%C", 0x0085, 0x000C, 0x2028, 0x2029]];
Run Code Online (Sandbox Code Playgroud)

Xcode在这里给我一个警告:

Format specifies type 'unsigned short' but the argument has type 'int'
Run Code Online (Sandbox Code Playgroud)

它建议我改变这一切%C%d,但是最终证明打破功能.这样做的正确方法是什么,为什么Xcode推荐错误的东西?

nie*_*bot 7

一种选择是将你的参数转换为unsigned short:ie (unsigned short)0x0085

但是如果你正在寻找换行符,你应该只使用换行符.这是"符合Unicode的":[ NSCharacterSet newlineCharacterSet ]

编辑

重温这个问题:如果你试图通过换行符分隔NSString/CFString,你应该使用-[ NSString getLineStart:end:contentsEnd:forRange:].