"ios" ReadOnly iOS under the introduction of combat

Source: Internet
Author: User

When very much XXX.h file attribute yy design, the external design is yy (readonly). The property cannot be changed by the outside world.

At the same time the problem also came, the XXX class can not change the internal changes to the YY attribute. Have you ever had a messy moment?

。。 Y_y

Then you'll find two ways to do it like this:

One: pointer

Never underestimate the power of the pointer, in the internal can be used in the obj->_yy way to change 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";    or _yyname = @ "skyming";

Second: declaring properties again

Seemingly very formal appearance, assume that their own write the class attributes are not many, the company has no other code specifications. placed directly in

I'll just declare it again.

Control it. Declaration 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
Suppose you have the same property. h files,. m files are all readonly, and you 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 within the company's internal SDK 、、、

Assuming your company's SDK is like this, just silently like it, y_y


"ios" ReadOnly iOS under the introduction of combat

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.