Mar*_*ery 5 xcode cocoa-touch objective-c uitableview ios
如果我在Xcode中使用以下代码声明并且不完整地实现我自己的协议:
SomeProtocol.h:
@protocol SomeProtocol <NSObject>
@required
-(void)someRequiredMethod;
@end
Run Code Online (Sandbox Code Playgroud)
SomeImplementor.h:
#import "SomeProtocol.h"
@interface SomeImplementor : NSObject <SomeProtocol>
@end
Run Code Online (Sandbox Code Playgroud)
SomeImplementor.m:
#import "SomeImplementor.h"
@implementation SomeImplementor { // I get a warning on this line
}
@end
Run Code Online (Sandbox Code Playgroud)
然后Xcode在@implementationSomeImplementor.h 的行上抛出一个警告,内容如下:
实施不完整.
协议中的方法'someRequiredMethod'未实现.
但是,如果我UITableViewDataSource使用以下代码从UITableView.h 不完整地实现协议...
SomeClass.h:
@interface SomeClass : NSObject <UITableViewDataSource>
@end
Run Code Online (Sandbox Code Playgroud)
SomeClass.m:
#import "SomeClass.h"
@implementation SomeClass { // I think I should get a warning here, but I don't
}
@end
Run Code Online (Sandbox Code Playgroud)
...然后Xcode很好用,并且不会在任何地方显示警告,即使我显然没有从UITableViewDataSource协议实现以下方法:
@protocol UITableViewDataSource<NSObject>
@required
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Run Code Online (Sandbox Code Playgroud)
为什么?我看不出有任何理由认为这两种情况应该区别对待.(而且我想要我的警告!)
| 归档时间: |
|
| 查看次数: |
617 次 |
| 最近记录: |