(IOS) understanding of @property and @synthesize (original)

Source: Internet
Author: User

When I started learning iOS, I didn't understand some of the OBJC grammars, like @property and @synthesize, before remembering and then using them, but writing more code, having some understanding of OBJC and iOS, plus the recent MRC, So in a variety of memory detection and variable use of the process, discussed, and finally the role of them have a certain understanding.

General @property and @synthesize are used in conjunction with @property declared variables, the system defaults to them to do setter and getter processing.

Property can declare various properties of an attribute.

1. declaring a property's access method:

    • Getter=gettername
    • Setter=settername
      Declares the setting of the Access property and gets the method name.

2. declaring attribute Write permissions:

    • ReadWrite
      Declares that this property is read-write, that is, you can access the Set method (setter), or you can access the Get method (getter), which is mutually exclusive with ReadOnly.
    • ReadOnly

Declares that this property is read-only and can only access the Fetch method (getter) corresponding to this property, which is mutually exclusive with ReadWrite.

3. implementation of declarative write methods

  4. atomicity of the access method

For atomicity, you can check the atomic operation of the operating system.

The name of a getter and setter that is not the same as the variable name can be defined in the @synthesize to protect the variable from inappropriate access.

  function: Let the compiler automatically write a method declaration with the same name as the data member, omitting the declaration of the read-write method.

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.