• 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: Subclasses, protocols and properties - compiler warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclasses, protocols and properties - compiler warning


  • Subject: Re: Subclasses, protocols and properties - compiler warning
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 19 Nov 2010 11:53:41 -0800

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 (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

References: 
 >Subclasses, protocols and properties - compiler warning (From: Jonny Taylor <email@hidden>)

  • Prev by Date: Re: Codesign failure
  • Next by Date: NSNotificationCenter not always working?
  • Previous by thread: Re: Subclasses, protocols and properties - compiler warning
  • Next by thread: Re: Subclasses, protocols and properties - compiler warning
  • Index(es):
    • Date
    • Thread