简体   繁体   English

如何在Objective-C中创建对函数附加警告?

[英]How do you create attach a warning to a function in Objective-C?

I'm writing an SDK for iOS and would like to warn developers when using a function that it should be for debug only, not for their release builds. 我正在为iOS开发一个SDK,并希望在使用仅用于调试而非其发行版本的功能时警告开发人员。 I want the function to have a warning sign attached to it whenever it is used by the developers to remind them that they should not release the app with this function. 我希望该功能在开发人员用来提醒他们不要使用此功能发布应用程序时附加警告标志。

I know I could add the deprecated attribute to the function, but that would not be accurate. 我知道我可以将不推荐使用的属性添加到函数中,但这并不准确。 The method is not deprecated, it is a method for QA only and should not be in the wild for end users. 该方法未弃用,它仅用于质量检查,对于最终用户不应该大肆宣传。

只需将以下内容写在警告的位置即可。

#warning <insert whatever your warning text should be>

Surround your method with conditional compile statements: 用条件编译语句包围您的方法:

#ifdef DEBUG
- (void) myDebuggingMethod {
// stuff goes here
}
#endif

That way if they use it for a release build (where DEBUG is not defined), it will generate an error and not allow them to compile at all. 这样,如果他们将其用于发行版本(未定义DEBUG),它将生成一个错误,并且根本不允许他们进行编译。

You can also use this to surround your calls to this method so that the code will always build. 您也可以使用它来包围对此方法的调用,以便始终构建代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM