If I declare and do not fully implement my own protocol, using the following code in Xcode:
SomeProtocol.h:
@protocol SomeProtocol <NSObject> @required -(void)someRequiredMethod; @end
SomeImplementor.h:
#import "SomeProtocol.h" @interface SomeImplementor : NSObject <SomeProtocol> @end
SomeImplementor.m:
#import "SomeImplementor.h" @implementation SomeImplementor {
Xcode then issues a warning in the @implementation SomeImplementor.h line, which reads as follows:
Incomplete implementation.
The 'someRequiredMethod' method is not implemented in the protocol.
However, if I do not fully implement the UITableViewDataSource protocol from UITableView.h with the following code ...
SomeClass.h:
@interface SomeClass : NSObject <UITableViewDataSource> @end
SomeClass.m:
#import "SomeClass.h" @implementation SomeClass {
... then Xcode does a great job of this and doesn’t issue a warning anywhere, although I obviously haven’t implemented the following methods from the UITableViewDataSource protocol:
@protocol UITableViewDataSource<NSObject> @required - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; // Row display. Implementers should *always* try to reuse cells by setting each cell 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;
Why? I see no reason why these two cases should be treated differently. (And I want my warnings!)
ios objective-c cocoa-touch xcode uitableview
Mark amery
source share