ios - Best Practice: When to use a delegate or not? NSXMLParserDelegate vrs NSURLConnection -
i implementing simple twitter client learning example.
my controller implements nsxmlparserdelegate custom implementations series of events/callbacks. likewise, implement series of callbacks nsurlconnection. don't understand why former delegate , latter not. feels both event handler classes , both delegates. have read best practices on msdn , think both implemented delegates. missing here? matter?
@interface simpletwitterclientviewcontroller : uiviewcontroller <nsxmlparserdelegate> { // event handlers/callbacks nsxmlparser delegate - (void)parserdidstartdocument:(nsxmlparser *)parser; - (void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qualifiedname attributes:(nsdictionary *)attributedict; - (void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname; - (void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string; - (void)parserdidenddocument:(nsxmlparser *)parser; // event handlers/callbacks url connection - (void) connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data; - (void) connection:(nsurlconnection *)connection didfailwitherror: (nserror *)error; - (void) connectiondidfinishloading: (nsurlconnection*) connection; }
both are implemented delegates. you're looking @ code , guessing name instead of reading apple documentation. when see <somenamehere>
, protocol. delegate conforms it, why protocol named somethingdelegate
. it's not called because it's delegate.
nsurlconnection uses informal protocol delegate rather formal one. means system takes word when use object delegate rather checking implement relevant methods. i'm not aware of particular reason why case. it's better use formal protocols when implement delegate systems yourself, it's not necessary.
don't bother reading documentation on msdn. c#, not objective c. read documentation on apple's developer center.
Comments
Post a Comment