Le 16 mars 09 à 15:21, Jeremy Pereira a écrit :


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)



Wow you're right. I think I missed something when I tried that just before posting my previous post (I probably forgot to inherit NSObject in my quick test).



_______________________________________________

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

Reply via email to