Access to OC member variables and point syntax

Source: Internet
Author: User

I. Accessing member variables using the _ member variable name

In a method, you can use the _ member variable name to access member variables in this object.

Note the point:

The 1> member variable must be a member variable in this object

2> This is not possible if the member variable is inherited from a parent class and this member variable in the parent class is set to @private.

3> can be used in conjunction with the & address character

Two. Accessing member variables using the Get Set method

Write a method that is dedicated to assigning values and values to access the member variables

Note the point:

The 1>set get method must be an object method, called by an object, to access the member variables inside the object. You must have an object, or get an object, to use Get,set

2>set is an assignment method, and get is the value method. The Get method has a return value that returns the specific value of this member after the call, so it cannot be used with the & accessor.

3> in principle as long as there are objects, or get the object can use the Get Set method, but if the class is only set,get implementation, no declaration, then Get,set is the private method of this class, can only be used in this class, not used outside the class, and even subclasses are not available.

Three. Using the. Grammar

The. syntax is called the Set,get method at precompilation, so the essence is the Set,get method

Note the point:

1> to use point syntax to ensure that there are objects, or to get the object

2> to use. Syntax you must ensure that there are set,get methods for member variables

3> point syntax cannot be used with the & address, for the same reason as Set,get

Four. Using pointers

Assign a member variable in a way that uses the pointer "object name->_ member name"

Note the point:

1> when a member is @public, you can access the member directly from the outside using the pointer method

2> when a member is @protected, it cannot be used outside the class, can be used in a class, subclass, or in other classes, but only if the object must be obtained.

3> You cannot use this method in a subclass when the member is @private, you can only access it by using the Get,set method.

Self,super, can be used flexibly in programming, with pointer method, Set,get method.

Access to OC member variables and point syntax

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.