Old code gives "Unused parameter" error but never has before now

Go To StackoverFlow.com

8

I've opened up some old iOS code and when I try to build it I get an "unused parameter" error for code like this:

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
    NSLog(@"Search Bar isn't used in this function");
}

This is the first time I've ever seen an Objective-C compiler spit out errors (not warnings) for this. Since a lot of iOS calls don't necessarily use the passing arguments (examples being a lot of callbacks), I need help in getting rid of this.

2012-04-04 17:06
by sparkFinder


13

Solution # 1)

In your Xcode project's "Build Settings", there's a parameter for "Unused Parameters".

Reset that from YES to NO. Unused Parameters Warnings

Solution # 2 (available with Xcode 4):

In Xcode 4.3.2 or higher use __unused.

(THANKS to Tim Bodeit's comment below)

Solution # 3)

Put #pragma unused (searchBar) in your code, preferably right underneath the line in your implementation where the function is declared.

I.E.

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
    #pragma unused (searchBar)
    NSLog(@"Search Bar isn't used in this function");
}
2012-04-04 17:08
by Michael Dautermann
Hi Michael, the XCode setting for the unused parameter warning already reads 'NO'. I'm really hoping not to have to inject code everywhere. Is there some other compiler (or other) setting I can look into - sparkFinder 2012-04-04 17:28
does the Setting read "NO" under the Resolved column for your target (not just the project)? Also, do you have "treat warnings as errors" set to yes in your project or target settings - Michael Dautermann 2012-04-04 17:36
It's listed as 'NO' in every column for both the project and the target. Treat warnings as errors is set to 'NO' in both as well - sparkFinder 2012-04-04 17:46
hmmmmmmmmmmmmm... you may want to edit your question to include the Build Log output of some of the errors you're seeing. I'm running out of ideas here - Michael Dautermann 2012-04-04 17:59
So I've gotten rid of the error by removing -Werror and -Wextra. The first tag makes warnings turn into errors. I don't like to have this off right now but I'm stuck. Going to accept your answer - sparkFinder 2012-04-04 18:09
I had to remove -Wall on older third party projects with the latest XCode 5.1 update or I'd get "unused warnings" into compiler errors even if I disable that particular warning in the project itself or as an independent flag - Robin R 2014-03-16 16:03
CORRECTION ^^ Above: The actual reason was "treat errors as warnings" compiler flag was enabled and Xcode has new warnings that it did not before so thus new errors showed up. Removing -Wall just made these new warnings disappear and thus not causes errors - Robin R 2014-03-16 16:41
The solution #2 is great - Beto 2014-03-24 22:02
In Xcode 4.3.2 or higher use __unused http://stackoverflow.com/a/10578498/198438 - Tim Bodeit 2015-05-06 13:22
Ads