Old code gives “Unused parameter” error but never has before now

与世无争的帅哥 提交于 2019-12-06 23:55:28

问题


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.


回答1:


Solution # 1)

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

Reset that from YES to NO.

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");
}


来源:https://stackoverflow.com/questions/10015974/old-code-gives-unused-parameter-error-but-never-has-before-now

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!