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


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

查看所有标签

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

Algorithms of the Intelligent Web

Algorithms of the Intelligent Web

Haralambos Marmanis、Dmitry Babenko / Manning Publications / 2009-7-8 / GBP 28.99

Web 2.0 applications provide a rich user experience, but the parts you can't see are just as important-and impressive. They use powerful techniques to process information intelligently and offer featu......一起来看看 《Algorithms of the Intelligent Web》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

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

UNIX 时间戳转换

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具