[Objective-c] Simple implementation of an OC class

Source: Internet
Author: User

I. Grammatical specifications

1. Class: Abstract description of a thing, such as the abstraction of humans, dogs and cats into animal classes

Two files in OC to describe a class

1>. H: declaration file for a class declaring member variables and methods, the declaration code of a class between keywords @interface and @end ;

2>. M: the implementation file for the class that implements the method in the. h file, the declaration code of the class between the keyword @implementation and the @end ;

Note: The methods in the. h file only participate in declarations and do not participate in implementations; that is, only method types, method return value types, method names, method parameter types, and method internal code are not written

2. Method:

Classification of 1> methods

    • +: Represents a class method (static method)
    • -: Represents an object method (dynamic method)

Example:

Object methods
-(ID) initwithdict: (Nsdictionary *) dic;//class method + (ID) initwithdict: (Nsdictionary *) dic;

2> the scope of all methods in the. h file is the public type

3. Member variables

There are 3 common scope of member variables:

1> @public can be accessed globally
2> @protected can only be accessed within the class and in subclasses
3> @private can only be accessed within the class

[Objective-c] Simple implementation of an OC class

Related Article

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.