开发者

Format not a string literal

开发者 https://www.devze.com 2023-03-09 23:23 出处:网络
I would appreciate understanding how to rewrite this line of code to elim开发者_StackOverflow社区inate the compiler warning. The code is:

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

精彩评论

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