After learning Java, C + + language, and then learn OC language, although also is the object-oriented language, but OC language still gives us a very "weird" feeling. This is mainly because the OC language itself has its own unique naming and use methods. Summing up the use of Java syntax and OC syntax, we will find that there are still many rules to follow. Some of the features of the OC class are summarized below.
First, about OC class
1.oc typically uses two files to describe a class that is different from Java.
2. The suffix. h file is a declaration file for a class that declares member variables, methods. Use keywords @interface and @end; Moreover, the. h file is declared only and does not implement the method of the class;
3. The suffix. m file is the implementation file for the class that implements the method declared in. h. Use keywords @implementation and @end;
Second, OC in the method
1. The Declaration and implementation of the method must begin with "+" and "-";
A plus sign represents a class method, a static method, and a minus sign represents an object method, that is, a dynamic method
2. The method declared in suffix. h is of type public and cannot be changed
method section (+/-) + return value type + method name :+ parameter type + parameter name
Third, member variables
1. The scope of the member variable consists of three
@public can be accessed globally
@protected can only be accessed within the class and within subclasses
@private can only be accessed within the class
Less scope than Java because there is no concept of a package in OC
Iv. Use of nnstring
1.%@ can be used on any object in the output format because it uses the-(nnstring*) Description Method (inherited from the NSObject class)
2.utf8string: Convert NSString object to C string, can be printed with%s
3.NSString * variable name, pointing to a constant pointer, equivalent to char *;
OC Object-oriented first OC class