A little bad idea of IOS for ReadOnly

Source: Internet
Author: User

When a lot of XXX.h file attributes yy design, the external design is yy (readonly), the outside world can not modify the property,

At the same time, the problem also came, the XXX class can not modify the internal changes to YY properties, you have an instant messy ... Y_y

Then we found the following two ways:

One: pointer

Never underestimate the power of the pointer, in the internal can be modified by the obj->_yy of the YY property, this way is also true

It's a little bit yy.

    Instantly turn red with wood//self    . Yyname = @ "skyming";        Self->_yyname = @ "skyming";    

Two: Re-declaring attributes

Seemingly very formal appearance, if you write the class attributes are not many, the company does not have any other code specifications, directly placed in

Re-declare it again in. M.

Let's compare the statement in H.

@interface Xxx:nsobject@property (nonatomic, ReadOnly, strong) NSString *yyname; @end

The declaration in. M @interface XXX () @property (nonatomic, ReadWrite, strong) NSString *yyname; @end
If you have readonly in the same property,. h files,. m files, you will get an error.


Of course, if the attribute is more, or in the SDK, then directly write a private. h Bar

And that's how it's done in many of the company's internal SDKs 、、、

If your company's SDK is like this, you silently praise it, y_y


A little bad idea of IOS for ReadOnly

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.