学习电脑,计算机系统故障维护,电脑技术,电脑知识学习-就上第二电脑网
当前位置: 首页 > 电脑知识 > 电脑基础

电脑diQ&A: HOW TO FIX XCODE’S "USED AS THE NAME OF THE PREVIOUS PARAMETER&q

 更新时间: 2019-08-13 18:05:47   作者:第二电脑网   来源:第二电脑网   浏览数:173   我要评论

Q&A: HOW TO FIX XCODE’S "USED AS THE NAME OF THE PREVIOUS PARAMETER&q,有需要的朋友可以参考下。:问题的核心在于:没有按照Ob-C推荐的方法来声明多参数函数。省略了第二个

Q&A: HOW TO FIX XCODE’S "USED AS THE NAME OF THE PREVIOUS PARAMETER&q,有需要的朋友可以参考下。

:问题的核心在于:没有按照Ob-C推荐的方法来声明多参数函数。省略了第二个或是后面参数的参数名,只用到一个冒号和行参名称,这样就造成编译器(Xcode 4.6及以上)警告。下文一共提供了三种方法来解决这一问题。

When you upgrade to Xcode 4.6, you may find that you are getting a number of compiler warnings like this:

‘xxxxx’ used as the name of the previous parameter rather than as part of the selector

In this post I will show you why you’re getting this warning, how to fix it, or how to ignore it.

Why You’re Getting This Warning

This is typically caused by declaring a method without specifying a description of the parameter. For example, check out the following method declaration:

002pc.com对《电脑diQ&A: HOW TO FIX XCODE’S "USED AS THE NAME OF THE PREVIOUS PARAMETER&q》总结来说,为我们电脑常识很实用。

– (NSString *) getFormattedDateString:(NSDate *)date:(NSString *)formatString;

The intent of this code is to declare a method namedgetFormattedDateStringthat accepts two parameters

nameddateandformatString.

Because there is no space between date and the colon (:), the compiler gives the warning “‘date’ used as the name of the previous parameter rather than as part of the selector”.

How to Fix The Problem

There are two ways to solve this warning:

1. Put a space betweendateand the colon:

– (NSString *) getFormattedDateString:(NSDate *)date :(NSString *)formatString;

2. Add a description for theformatStringparameter:

– (NSString *) getFormattedDateString:(NSDate *)date withFormat:(NSString *)formatString;

The second option is preferable because it makes your method more readable. That;s because parameter descriptions are part of the method signature. In this example, the method signature is:

getFormattedDateString:withFormat:

If you leave out the parameter description, the method signature is the less readable:

getFormattedDateString::

How to Ignore the Warning

Although it’s preferable to fix these warnings by changing your method declarations, if you want to ignore them, you can simply add the following declaration to your project’s PCH file (located in the Support Files group):

#pragma clang diagnostic ignored “-Wmissing-selector-name”

这里还需要注意一点的是,Xcode 6.0及以上版本中创建工程时,为加快编译速度,已不默认添加.pch文件,这需要我们手动添加该文件。

版权声明:本文为博主原创文章,未经博主允许不得转载。


更多:电脑diQ&A: HOW TO FIX XCODE’S "USED AS THE NAME OF THE PREVIOUS PARAMETER&q
https://www.002pc.com/diannaojichu/922.html

你可能感兴趣的USED,NAME,FIX,HOW,PARAMETER,XCODE

    关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿

      浙ICP备140365454号

    ©CopyRight 2008-2020 002pc.COM Inc All Rights Reserved. 第二电脑网 版权所有 联系QQ:282523118