The Dark Horse program----OC dot syntax

Source: Internet
Author: User

-------<a href= "http://www.itheima.com" target= "blank" >android training </a> <a href= "/http/ Www.itheima.com "target=" blank ">java training </a>, look forward to communicating with you! ----------

dot Syntax1. Point syntax related to setter and getter

Person *p = [person new];

[P setage:10]; Equivalent to P.age = 10;

int a = [P age]; equivalent to int a = P.age;

2. Description:

P.age = 10; The member variable _age of the P object is not accessed, and even the member variable _age that accesses the P object should be written as P--_age; the correct meaning of this sentence is to invoke the Setage: method of the P object.

3.p.age = 10; the difference from p.age:

If there is an assignment, that is: P.age = 10, that is, the setage of the P object is called : method; no assignment, i.e. p.age; Represents the Getage method that called the P object:(int) age;

The only way to access member variables directly in 4.OC is with the arrow -, the point syntax does not represent the member variables of the direct Access object; 5. Analysis of the real function of point grammar
    • In fact, the point syntax is the invocation of the method ;
    • When the point syntax is used, the compiler automatically expands to the appropriate method ;

6. Use of Point syntax note that improper use of dot syntax can cause a dead loop:

The Dark Horse program----OC dot 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.