First OC Class

Source: Internet
Author: User

1. How do I declare a class?

Format:

1 @interface People:nsobject 2 {3      // instance Variable 4 }5     // declaration of class 6@end

Attention:

    1. Must start with @interface and end with @end.
    2. The declaration of the member variable must be written in curly braces between @interface and @end
    3. The declaration of the method must be under {} and cannot be written in {}

2. How do I implement a class?

Format:

1 @implementation people 2     // implementation of the class 3 @end

Attention:

    • 1. Must start with @implementation, @end end
    • 2. The class name must be consistent with the declaration

3. How do I create an object?

Example: people * p = [people new]

Attention:

[People new] has done three things:

    1. Opens up a new piece of storage space in heap memory
    2. Initializing a member variable (a property written in a class declaration brace is called a member variable, also known as an instance variable)
    3. Return pointer address

4. Points of attention of the object:

      • You can access the members of an object by using object-by-member (notice that the declaring property is: @public).
      • Each object has a property of its own.
      • A member of one of the objects was modified. Not related to another object

First OC Class

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.