objective-c – 让Xcode 4.3警告当前@implementation中存在的未声明的方法

栏目: Objective-C · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/9560650/make-xcode-4-3-warn-about-undeclared-methods-that-exist-in-the-current-implemen

当Xcode 4.3存在于当前时,Xcode 4.3不会对未声明的方法发出警告

@implementation,这是一个很棒的新功能.但是,在Xcode 4.2上使用我的项目时,这在某些情况下会导致问题.

如何重新启用未声明方法的警告?

例如:

@interface MashTun : NSObject
- (void)foo;
@end

@implementation MashTun
- (void)foo {
    CGRect rect = [self smallRect];
    NSLog(@"My Small Rect: %@", NSStringFromCGRect(rect));
}

- (CGRect)smallRect {
    return CGRectMake(0, 0, 100, 100);
}
@end

在Xcode 4.2中,这失败了:

warning: instance method '-smallRect' not found (return type defaults to 'id')
error: initializing 'CGRect' (aka 'struct CGRect') with an expression of incompatible type 'id'

我完全理解Xcode 4.2中的警告和错误,因为它不允许在当前的@implementation范围内搜索方法. (修复很简单:将smallRect方法放在foo方法之上,或者在类别或标题中声明smallRect方法.)

但是如何在Xcode 4.3中打开警告以捕获此错误,然后再将其传递给运行4.2的同事?

新的LLVM 3.1编译器并不关心这一点.如果您将方法置于上方/下方或是否有原型,则无关紧要.因此,如果所有同事的Xcode都更新到至少4.3.这真的不应该成为一个问题.

另一种选择是使用下面的代码创建自己的警告.你冷笑告诉他们这个问题,以及手边的问题.这可能是一种简单的方法来传达信息.

#warning "warning message"

希望这可以帮助.

翻译自:https://stackoverflow.com/questions/9560650/make-xcode-4-3-warn-about-undeclared-methods-that-exist-in-the-current-implemen


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

How to Think About Algorithms

How to Think About Algorithms

Jeff Edmonds / Cambridge University Press / 2008-05-19 / USD 38.99

HOW TO THINK ABOUT ALGORITHMS There are many algorithm texts that provide lots of well-polished code and proofs of correctness. Instead, this one presents insights, notations, and analogies t......一起来看看 《How to Think About Algorithms》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

随机密码生成器
随机密码生成器

多种字符组合密码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换