Re: Type Declaration With Protocol
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