[IOS] Some bad thoughts on readonly, iosreadonly
When many XXX. h file attributes are in YY design and the external design is YY (readonly), the external design cannot modify this attribute,
At the same time, the problem is that the XXX class cannot be changed to the YY attribute. Have you ever been messy... Y_Y
Then we can find the following two methods:
I. pointer
Never underestimate the power of pointer. You can use obj-> _ YY to modify the YY attribute internally. This method is also true.
A little human YY
// Instantly red/self. YYname = @ "skyming"; self-> _ YYname = @ "skyming ";
Ii. Re-declare attributes
It looks very formal. If there are not many class attributes written by myself, the company will not have any other code specifications and will directly put them in
Just redeclare again in. m.
Let's compare the statements in. h.
@ Interface XXX: NSObject @ property (nonatomic, readonly, strong) NSString * YYname; @ end
Declaration in. m @ interface XXX () @ property (nonatomic, readwrite, strong) NSString * YYname; @ end
If you have the same attribute, the. h file and. m file are all readonly, an error is returned.
Of course, if there are more attributes, or in the SDK, write a Private. h directly.
In addition, this is also true for sdks in many companies ,,,
If your company's SDK is like this, just like it, Y_Y