Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 675
sparkFinder Avatar asked Apr 04 '12 17:04

sparkFinder


1 Answers

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");
}
like image 199
Michael Dautermann Avatar answered Sep 19 '22 12:09

Michael Dautermann