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

Jes*_*ers 8 xcode objective-c clang compiler-warnings method-declaration

当Xcode 4.3存在于当前时 @implementation,Xcode 4.3不会对未声明的方法发出警告,这是一个很棒的新功能.但是,在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
Run Code Online (Sandbox Code Playgroud)

在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' 
Run Code Online (Sandbox Code Playgroud)

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

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

Vik*_*ngs 0

新的 LLVM 3.1 编译器不关心这一点。将方法放在上面/下面或者是否有原型并不重要。因此,如果您所有的同事都将 Xcode 更新到至少 4.3。这确实不应该是一个问题。

另一种选择是使用下面的代码创建您自己的警告。你冷酷地告诉他们这个问题和手头的问题。这可能是传达信息的简单方法。

#warning "warning message"
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助。