On Nov 19, 2010, at 06:38, Jonny Taylor wrote:

> @protocol MyProtocol <NSObject>
>       @property int genericProperty;
>       -(void)subclassSpecificImplementationOfGenericFunction;
> @end
> 
> @interface MyBaseClass : NSObject
>       @property int genericProperty;
> @end
> 
> @interface MySubclass : MyBaseClass <MyProtocol>
>       -(void)subclassSpecificImplementationOfGenericFunction;
> @end
> 
> @implementation MyBaseClass
>       @synthesize genericProperty;
> @end
> 
> @implementation MySubclass
>       -(void)subclassSpecificImplementationOfGenericFunction { return; }
>       // I find myself writing "@dynamic genericProperty" here to shut up the 
> compiler warning
>       // that reads "warning: property 'genericProperty' requires method 
> '-genericProperty' to be defined - use @synthesize, @dynamic or provide a 
> method implementation"
> @end

I believe GCC got stricter with this sort of thing fairly recently. Here's a 
similar example that I ran into, not involving protocols:

@interface MyClass : NSObject
        @property (readonly) int genericProperty;
@end

@interface MyMutableClass : MyClass
        @property (readwrite) int genericProperty;
@end

@implementation MyClass
        - (int) genericProperty {...}
@end

@implementation MyMutableClass
        // uses the inherited getter
        - (void) setGenericProperty: (int) newValue {...}
@end

IIRC, this used to compile without a warning, but now it complains that the 
getter isn't defined in MyMutableClass.

So, I think the problem you ran into isn't about protocols, but rather that 
adopting the protocol effectively declares the property in the subclass, which 
now requires a full implementation in the subclass, just like in my example.

AFAIK there is no way to determine if the warning is spurious, because there's 
no sufficiently detailed/complete ObjC language specification against which to 
ask the question. You could file a bug saying that you don't like the new 
behavior, I suppose.

FWIW I resorted to the same solution you did. I used to be mightily afraid of 
the mysterious @dynamic, but now it's my friend.


_______________________________________________

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