Can property memory management be changed if it is overridden in a class extension?

If I have a property like this:

//test.h @interface test @property (nonatomic, readonly, weak) NSObject x; @end 

redefined in the implementation file for reading / writing:

 // test.m @interface test () @property (nonatomic, readwrite) NSObject x; @end 

I used weak in .h, but I did not say anything in the extension, will the property contain a β€œweak” specifier, or will it change to β€œstrong”?

Will the strong / assign / weak keywords be overwritten when overriding a property?

+5
source share
1 answer

A simple test with Xcode 5.1.1 shows that the weak attribute is preserved. The same is true for assign and strong attributes - you can specify them in .h and omit them in .m if you include them in .m , which should match.

Having said that, I do not know if it is registered anywhere. But then the semantics of Objective-C are not formally defined anywhere. Therefore, use at your own risk.

Recommendation: just repeat it.

+5
source

Source: https://habr.com/ru/post/1210434/


All Articles