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