So, I have a protocol for which you want to declare a property:
@protocol MyProtocol <NSObject> @property MyView *myView; @end
and the object that corresponds to it:
@interface MyViewController : NSViewController <MyProtocol> @end
However, if I declare a property (specified in the protocol) inside the implementation file (class extension):
@interface MyViewController() @property MyView *myView; @end
I get this error:
Illegal redefinition of property into an extension of the "MyViewController" class (the attribute must be "readwrite" and its primary must be "readonly")
There seem to be two main streams of SO that address this:
the attribute should be readwrite, while its main part should be read only
and
Unable to declare another window
The first answer doesnβt explain anything.
The second answer says that you can really get around this error by declaring a property inside the header; and alas
Headline
@interface MyViewController : NSViewController <MyProtocol> @property MyView *myView; @end
Implementation
@interface MyViewController() @end
This happens without error.
I also know that when you declare @property inside a protocol, it is not automatically synthesized.
So, if I wanted to keep the @property declaration inside the implementation, I would have to @synthesize it. And it also works.
So my question is: why does the @property declaration inside the header or implementation file matter if @property was originally declared inside the protocol?
Without the protocol, I thought the only difference was that @property public or private. But it is clear that there are other things that happen / don't happen if you declare @property in the header or implementation file