Fra*_*ank 0 cocoa objective-c ios
代码构建一个警告并生成预期输出"Hello,World!"
示例文件"TestClass.h"
#import <Cocoa/Cocoa.h>
@interface TestClass : NSObject {
}
- (void)foobar;
@end
Run Code Online (Sandbox Code Playgroud)
示例文件"TestClass.m"
#import "TestClass.h"
@implementation TestClass
- (void)say {
// Compiler output "warning: 'TestClass' may not respond to '-hello'"
[self hello];
}
- (void)hello {
NSLog(@"Hello, World!");
}
- (void)foobar {
[self say];
}
@end
@interface TestClass ()
- (void)say;
- (void)hello;
@end
Run Code Online (Sandbox Code Playgroud)
通过在@implementation部分中将"hello"方法置于"say"之上,可以避免编译器警告.但是依赖于你的方法的顺序是令人讨厌的.有没有办法绕过这个编译器警告,而不必按任何特定的顺序放置你的方法?
不,没有.期间.
编译器解析代码自上而下的,所以请,只要把你的私人@interface确定指标上面你@implementation,你会被所有的好去.
| 归档时间: |
|
| 查看次数: |
475 次 |
| 最近记录: |