Se io dichiaro e non completamente realizzare il mio proprio protocollo utilizzando il seguente codice in Xcode:Perché Xcode 4 non lancia un avvertimento sulla mia implementazione incompleta del protocollo UITableViewDataSource?
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 { // I get a warning on this line
}
@end
Poi Xcode lancia un avvertimento sulla linea di SomeImplementor.h @implementation
, che recita come segue:
incompleta attuazione.
Metodo 'someRequiredMethod' nel protocollo non implementato.
Tuttavia, se non completamente implementare il protocollo UITableViewDataSource
dal UITableView.h con il seguente codice ...
SomeClass.h:
@interface SomeClass : NSObject <UITableViewDataSource>
@end
SomeClass.m :
#import "SomeClass.h"
@implementation SomeClass { // I think I should get a warning here, but I don't
}
@end
... allora Xcode è bene con esso, e non visualizza un messaggio di avviso da nessuna parte, anche se chiaramente non hanno applicato i seguenti metodi dal protocollo 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;
Perché? Non vedo alcun motivo per cui questi due casi debbano essere trattati in modo diverso. (E voglio che i miei avvertimenti!)
@MarkAmery Molto interessante. Sto vedendo gli stessi risultati. – rmaddy
Questa domanda è un duplicato di http://stackoverflow.com/questions/14038381/compile-warnings-about-missing-required-protocol-methods-not-appearing –
@Jai: Ma nota che quella domanda non ha una risposta accettata, e questa domanda aggiunge informazioni più preziose. Quindi consiglierei ** NOT ** di chiudere come duplicato. –