Re: Xcode warns about missing protocol definition, even though @protocol is used
Re: Xcode warns about missing protocol definition, even though @protocol is used
- Subject: Re: Xcode warns about missing protocol definition, even though @protocol is used
- From: Florian Pilz <email@hidden>
- Date: Tue, 17 Apr 2012 07:05:06 +0200
A thanks, that explains a lot. I'm just a bit confused why the compiler needs to know the declared methods in the header file - I can't imagine a case where a protocol method is 'used' in the header. In the implementation file it's clear to me that the protocol must be known, however it's imported there so that shouldn't be an issue.
-- Florian Pilz
On Monday, 16 April 2012 at 23:28, Uli Kusterer wrote:
> On 16.04.2012, at 23:03, Florian Pilz wrote:
> > The import is done in the ".m"-file of HomeTableViewController. But I just found a fault in my sample code anyways: the ".h"-file of HomeTableViewController should have an "@protocol NewFooController" declaration.
> >
> > Corrected sample code for HomeTableViewController.h:
> >
> > #import <UIKit/UIKit.h>
> > @protocol NewFooControllerDelegate;
> > // warning points to line below
> > @interface HomeTableViewController : UITableViewController <NewFooControllerDelegate>
> > @end
> >
>
>
>
> That won't work. When you declare a class as conforming to a protocol, the compiler has to know what methods that protocol contains, so it can make sure to complain if one of the required methods is missing.
>
> @protocol Foo only works if you want to declare a variable of type id<Foo> (but not actually send messages to it). It simply tells the compiler "this protocol exists", but not what methods it actually consists of.
>
> It's the same as with plain C struct Foo; and struct Foo { int x; int y; }; Only the latter can actually be used (because now the compiler knows that there is a struct named 'Foo'), but you can declare pointers to the former, because for a pointer it only has to know the size of an address, not the size of the struct at that address.
>
> Cheers,
> -- Uli Kusterer
> "The Witnesses of TeachText are everywhere..."
> http://www.masters-of-the-void.com
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden