开发者

Format not a string literal

I would appreciate understanding how to rewrite this line of code to elim开发者_StackOverflow社区inate the compiler warning. The code is:

if (string == nil)
        [NSException raise:NSInvalidArgumentException format:nil];

The warning is:

Format not a string literal and no format arguments.

I found answers pertaining to NSLog, but not to NSException.

JAL


That error applies to anything which expects a format string. You simply need to replace nil with @"", as in:

[NSException raise:NSInvalidArgumentException format:@""];


This is because the compiler expects a format string(of type @"%@"), not a string literal(constant string) for the format parameter. Try giving an empty string @"" it should work.

[NSException raise:NSInvalidArgumentException format:@""];

This is better explained here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜