Pre-preparation for OC language
I. INTRODUCTION of OC
OC language on the basis of the C language, the addition of a layer of the smallest object-oriented syntax, fully compatible with the C language, in the OC code, can be mixed with C, or even C + + code.
You can use OC to develop applications for Mac OSX platforms and iOS platforms.
Extended Name: C language-.c OC language.-M compatible c++.-mm
Note: In fact, C language and OC or even any language is just for us to achieve some functions, to achieve some effect and the use of tools, aside from the grammatical differences, I think the most important thing is to solve the problem when the angle and method of thinking is different, but this also constitutes the importance of learning a language.
Second, Syntax preview
(i) Keywords
Basically all of the keywords are at the beginning of the (in order to distinguish with the C keyword), such as @interface @implementation @public, and so on, a small part does not start with @, such as id,_cmd, etc.
(b) The string begins with @
C-language string: "Hello"
OC language string: @ "Hello"
(iii) Other grammatical
Basic type: 5 types, added Boolean type
Nil equals null, which is 0.
Screen output: NSLog (@ "Hello");//Wrap Line
NSLog (@ "Age is%d", 2);
Third, OC program development process
#import预处理指令有两个作用: (1) As with # include, the Copy file contents (2) can automatically prevent the contents of the file from being copied repeatedly
The program compiles the connection process:
source file (. m)---(compile)----> destination file (. 0)-----(link)----> executable (. Out)
Foundation Framework. What should I do if I want to use all the header files in the frame? Contains the primary header file for the framework. The primary header file is the most important header file in a framework, with the main header filename and frame name consistent for each frame.
such as #import<foundation/foundation.h>
Run the following procedure:
(1) Write the OC source file. M. C
(2) Compiling files cc-c xx.m xxx.c
(3) Link cc xx.o xxx.o-framework Foundation
(4) run./a.out
Iv. Types of Supplements
Int Main ()
{
BOOL B=yes;
BOOL B1=no;
BOOL b2=1;//YES
BOOL b3=2;//NO
NSLog (@ "%i", b);
}
The bool type is consistent with other types of usage, and the nature of the bool type is char type, defined as follows:
Typedef signed Char BOOL
Macro definition:
#define YES (BOOL) 1
#define NO (BOOL) 0
The output of a Boolean type is generally used as an integer.
Pre-preparation for OC language