Warning unused parameter

I get a "unused parameter" testString "warning" from the following code. But I use testString to register. So why is this not used?

- (void)getString:(NSString *)testString { ICELogInfo(@"%@", testString); } 

ICELogInfo is a macro for NSLog.

 #define ICELogInfo(fmt, ...) LOG_FORMAT(fmt, @"INFO", ##__VA_ARGS__) #define LOG_FORMAT(fmt, lvl, ...) LOG_FORMAT_NO_LOCATION(fmt, lvl, ##__VA_ARGS__) #define LOG_FORMAT_NO_LOCATION(fmt, lvl, ...) NSLog((@"%@ " fmt), lvl, ##__VA_ARGS__) 

What am I doing wrong?

+4
source share
3 answers

You are not doing something wrong. This is a common problem when using macros.

As a workaround, if you want to get rid of the warning, you can use this code:

 - (void)getString:(NSSTring*) __unused testString { ICELogInfo(@"%@", testString); } 
+4
source

I faced the same "problem". Solved it using unused flag e.g.

 - (void)getString:(NSString *)testString { ICELogInfo(@"%@", testString); #pragma unused (testString) } 
+2
source

What version of Xcode are you using? This looks like a lambda capture error in LLVM over a year ago:

[LLVMbugs] [Error 12153] New: incorrect warning about an unused parameter when using the variation parameter in lambda

since the VA_ARGS in these macros is expected to work with the same problem described in this error report; but it should be allowed in recent Xcodes. Specifically, in Xcode 5 DP 3, which I'm running right now, your code does not give me any warnings.

0
source

Source: https://habr.com/ru/post/1490550/


All Articles