The short version is that I have a protocol which has an optional parameter. When I build a class that implements it with the iPhone SDK 3.x it compiles just fine, with no errors or warnings. When I used the 2.x SDK I get the following warning:
Class.m:68: warning: property 'field' requires method '-field' to be defined - use @synthesize, @dynamic or provide a method implementation
It works just fine in both cases.
So two questions:
- What is the right way to fix the warning? I added
@dynamic
to the implementation which isn't really correct as the property really isn't there. - Why does work in SDK 3.x but not 2.x? The docs say "On Mac OS X v10.5, protocols may not include optional declared properties." Clearly that's not exactly the case here.
Here's a quick sample of the kind of code I have to make things a little more obvious if I wasn't completely clear.
@protocol MyProtocol
@required
- (void) method:(NSString*)param;
@optional
@property (nonatomic,retain) NSString* field;
@end
@interface MyClass : NSObject<MyProtocol> {
}
- (void) method:(NSString*)param;
@end