Le 20 nov. 2009 à 20:46, Michael de Haan a écrit : > I am working through an example in Buck/Yacktman's book that uses an > informal protocol. > > In the interface of of a custom class, it is declared as such. > > > #import <Cocoa/Cocoa.h> > > > @interface MyShapeEditorDocument : NSDocument > { > ....ivars.... > } > @end > > > @interface NSObject(MYShapeEditingDocEditor) > > > > -(void) controllerDidEndEditing; > @end > > > In the implementation file it is defined, twice, thus. > > > @implementation NSObject(MYShapeEditingDocEditor) > > -(void) controllerDidEndEditing > { > > } > @end > > and in the main body of the code, thus. > > > @implementation MyShapeEditorDocument > > > -(void) controllerDidEndEditing > { > [[self myView] setNeedsDisplay: YES]; > [[self table] reloadData]; > } > > > Apple's docs say: "When used to declare a protocol, a category interface > doesn’t have a corresponding implementation. Instead, classes that implement > the protocol declare the methods again in their own interface files and > define them along with other methods in their implementation files." > (http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/ObjectiveC/Articles/ocProtocols.html#//apple_ref/doc/uid/TP30001163-CH15-TPXREF147) > > > What I am not following is the seemingly double definitions. From the docs, > it would seem that implementation is a 2 step process, not a 3 step as above, > even though this is clearly correct. What is the essence that I am missing?
The usual way is to NOT implements the NSObject category and test if the delegate implements the method using -respondsToSelector: But this way works too if you don't want to have to test before sending your message. Anyway, informal protocols are "deprecated" in favor of @protocol with @optional method. -- Jean-Daniel _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com