• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Xcode warns about missing protocol definition, even though @protocol is used
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Uli Kusterer <email@hidden>
  • Date: Mon, 16 Apr 2012 23:28:29 +0200

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

  • Follow-Ups:
    • Re: Xcode warns about missing protocol definition, even though @protocol is used
      • From: Florian Pilz <email@hidden>
References: 
 >Xcode warns about missing protocol definition, even though @protocol is used (From: Florian Pilz <email@hidden>)
 >Re: Xcode warns about missing protocol definition, even though @protocol is used (From: Kyle Sluder <email@hidden>)
 >Re: Xcode warns about missing protocol definition, even though @protocol is used (From: Florian Pilz <email@hidden>)

  • Prev by Date: Re: Xcode warns about missing protocol definition, even though @protocol is used
  • Next by Date: Resizing UITableView will keeping content scrolled to bottom
  • Previous by thread: Re: Xcode warns about missing protocol definition, even though @protocol is used
  • Next by thread: Re: Xcode warns about missing protocol definition, even though @protocol is used
  • Index(es):
    • Date
    • Thread