8

Xcode 4.3 在 current 中存在未声明的方法时不会发出警告 @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 的同事?

4

3 回答 3

0

The new LLVM 3.1 compiler does not care about this. It does not matter if you place the method above/below or whether there is a prototype. So if all your colleagues have their Xcode updated to at least 4.3. This really should not be an issue.

Another option is to create your own warning using the code below. You cold inform them of this issue, and problem at hand. This might be an easy way to get the message across.

#warning "warning message"

Hope this helps.

于 2012-03-14T01:37:28.307 回答
0

在这种过渡期间的一个选择是与另一个编译器/版本交叉编译。gcc-llvm 是一种常见的预安装替代方案。另一种方法是安装多个版本的 xcode 并使用该工具链进行构建。

于 2012-07-10T18:33:23.183 回答
0

我不知道我是否有一个有趣的构建,但我的 LLVM 3.1 编译器在编译器警告下确实有未声明的选择器标志。目前正在运行 4.3.2。LLVM 4.0 虽然没有它。

于 2012-07-10T16:25:13.380 回答