Protocols cannot decide or change behaviour of an object. Instead, it is up to the object in question to adopt the protocol appropriately. Declaring methods as @optional just means that you have a choice whether to implement or not. Anyone wanting to call the method should first check if its implemented with -respondsToSelector:
On 5 Jan 2010, at 18:53, John Michael Zorko wrote: > > Hello, all ... > > After [re-]reading the Apple documentation, i'm still not clear as to what > @optional really does in a @protocol. I thought that declaring certain > messages as @optional would make the app not crash if a certain message > didn't have an implementation in a class that adopts the protocol, however > i'm finding that this isn't the case: > > 2010-01-05 10:40:58.698 VoxityNowPlaying[14413:207] *** Terminating app due > to uncaught exception 'NSInvalidArgumentException', reason: '*** > -[VoxityNowPlayingViewController playerURLFinished:]: unrecognized selector > sent to instance 0x39138f0' > > ... yet my protocol is defined thusly: > > @protocol VoxityPlayerDelegate <NSObject> > > @optional > > - (void)playerURLFinished:(NSURL *)url; > > . > . > . > > @end > > Do I need to wrap code that sends messages to delegates with > -respondsToSelector? If so, what is the point of @optional in the protocol? > > Regards, > > John > > > _______________________________________________ > > 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/cocoadev%40mikeabdullah.net > > This email sent to cocoa...@mikeabdullah.net _______________________________________________ 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