旧代码给出“未使用的参数”错误,但从来没有现在 [英] Old code gives "Unused parameter" error but never has before now
问题描述
我打开了一些旧的iOS代码,当我尝试构建它我得到一个未使用的参数错误代码如下:
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
NSLog(@Search Bar is not used in this function);
}
这是我第一次看到Objective-C编译器吐出错(不是警告)。因为很多iOS调用不一定使用传递的参数(例子是很多回调),我需要帮助消除这个。
解决方案#1)
在Xcode项目的Build Settings中,有一个Unused Parameters参数。
重置为从 YES
到 NO
。
2(可用Xcode 4):
在Xcode 4.3.2或更高版本中,使用 __未使用
解决方案3)
在您的程式码中加入 #pragma unused(searchBar)
$ b code> - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
#pragma unused(searchBar)
NSLog(@Search Bar is not used in this function
}
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.
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");
}
这篇关于旧代码给出“未使用的参数”错误,但从来没有现在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!