使命名错误的选择器产生编译时错误 [英] Making a misnamed selector generate a compile time error

查看:72
本文介绍了使命名错误的选择器产生编译时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在objective-c 中,我怎样才能让一个命名错误的选择器产生一个编译时错误?

In objective-c how can I make a misnamed selector generate a compile time error?

例如,假设我有这个

 @selector(some_misnamed_func)

我的班级有这个成员

  -(void)some_func

我希望 Objective-c 编译器告诉我它在编译时找不到该函数,而不是仅在运行该代码时才生成运行时异常.

I want the objective-c compiler to tell me that it can't find that function at compile time rather than generate a run-time exception only when that code is run.

推荐答案

在 Xcode 的构建设置中使用 -Wundeclared-selectorUndeclared selector 编译您的代码.由于这只是一个警告,您可以将它与 -Werror(在 Xcode 中分别将警告视为错误)结合起来,使该警告(以及所有其他警告)表现为错误并有效地中止编译.

Compile your code with -Wundeclared-selector, or Undeclared selector in Xcode’s build settings. Since that’s a warning only, you can couple it with -Werror (resp. Treat Warnings as Errors in Xcode) to make that warning (and all other warnings) behave as an error and effectively abort the compilation.

这篇关于使命名错误的选择器产生编译时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆