• 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: Type Declaration With Protocol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Type Declaration With Protocol


  • Subject: Re: Type Declaration With Protocol
  • From: Jeremy Pereira <email@hidden>
  • Date: Mon, 16 Mar 2009 14:21:09 +0000


On 16 Mar 2009, at 12:10, Jean-Daniel Dupas wrote:


No, you can't, else the compiler will complains if you do not override all NSObject protocol methods in classes that conform to the Foo protocol.

No it shouldn't. The compiler should only complain if your class does not implement those methods, which of course it does as it inherits from NSObject.



I don't know if it should or not, but it does.

No it doesn't. For instance:

@protocol FooProt <NSObject>
-(void) foo ;
@end

@interface Foo : NSObject <FooProt>
{

}
@end

@implementation Foo
@end

id<FooProt> aFunction ()
{
	id<FooProt> obj = [[Foo alloc] init] ;
	[obj autorelease] ;
	return obj ;
}


The compiler complains about the missing implementation of foo but not any of the NSObject protocol methods.


/Users/jeremyp/dev/Perform/Protocol.m:26: warning: incomplete implementation of class 'Foo'
/Users/jeremyp/dev/Perform/Protocol.m:26: warning: method definition for '-foo' not found
/Users/jeremyp/dev/Perform/Protocol.m:26: warning: class 'Foo' does not fully implement the 'FooProt' protocol


But change the protocol definition as follows:

@protocol FooProt
-(void) foo ;
@end

And these are the warnings:

/Users/jeremyp/dev/Perform/Protocol.m:26: warning: incomplete implementation of class 'Foo'
/Users/jeremyp/dev/Perform/Protocol.m:26: warning: method definition for '-foo' not found
/Users/jeremyp/dev/Perform/Protocol.m:26: warning: class 'Foo' does not fully implement the 'FooProt' protocol
/Users/jeremyp/dev/Perform/Protocol.m: In function 'aFunction':
/Users/jeremyp/dev/Perform/Protocol.m:31: warning: '-autorelease' not found in protocol(s)






_______________________________________________

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

_______________________________________________

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: Type Declaration With Protocol
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >Type Declaration With Protocol (From: Richard Somers <email@hidden>)
 >Re: Type Declaration With Protocol (From: Roland King <email@hidden>)
 >Re: Type Declaration With Protocol (From: Jeremy Pereira <email@hidden>)
 >Re: Type Declaration With Protocol (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Type Declaration With Protocol (From: Mike Abdullah <email@hidden>)
 >Re: Type Declaration With Protocol (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: Re: Messages between Threads
  • Next by Date: Re: case-insensitive NSDictionary
  • Previous by thread: Re: Type Declaration With Protocol
  • Next by thread: Re: Type Declaration With Protocol
  • Index(es):
    • Date
    • Thread