> On Feb 18, 2015, at 8:41 PM, Jens Alfke <[email protected]> wrote:
> 
> 
>> On Feb 18, 2015, at 5:34 PM, Greg Parker <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> There's no such thing as an optional property nor a class property in a 
>> protocol. All properties in a protocol are required instance properties.
> 
> Wait, what? I’ve used optional properties in protocols before; and just to 
> make sure, I wrote a little example:
> 
> @protocol YYY
> @property int req;
> @optional
> @property int opt;
> @end
> 
> @interface ZZZ : NSObject <YYY>
> @end
> 
> @implementation ZZZ
> @synthesize req;
> @end
> 
> @interface ZZZBad : NSObject <YYY>
> @end
> 
> @implementation ZZZBad
> @end
> 
> Compiling this in Xcode 6.3beta, with auto property synthesis turned off, 
> produces:
> 
> test.m:55:17: error: auto property synthesis will not synthesize property 
> 'req' declared in protocol 'YYY' [-Werror,-Wobjc-protocol-property-synthesis]
> @implementation ZZZBad
>                 ^
> test.m:40:15: note: property declared here
> @property int req;
>               ^
> 1 error generated.
> 
> In other words, class ZZZ compiles because the missing property ‘opt’ is 
> declared optional; but class ZZZBad fails because it doesn’t implement the 
> required property ‘req’.

Interesting, I didn't know the compiler had added that. In any case the 
metadata representation only has a slot for required instance properties, so 
there's still no way for you to know at runtime. You should file a bug report 
to get optional property metadata added to the compiler and the runtime.


-- 
Greg Parker     [email protected] <mailto:[email protected]>     Runtime 
Wrangler


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/objc-language/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to