[IOS] Some bad thoughts on readonly, iosreadonly

Source: Internet
Author: User

[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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.