"IOS development" "OC" 00, ios "oc 」
1. OC Introduction
On the basis of the C language, a minimum object-oriented syntax is added. It is fully compatible with C language. It can be mixed into C language code or even C ++ code in OC code; you can use OC to develop Mac OS X and iOS applications.
Ii. OC syntax Preview
(1) KEYWORDS
Basically, all keywords start with @, such as @ interface @ implementation @ public. A few keywords do not start with @, such as id and _ cmd.
(2) The string starts @
C language string: "hello"
OC language string: @ "hello"
(3) Other syntaxes
Basic types: 5. boolean BOOL (YES/NO) is added ).
Nil is equivalent to null in C, that is, 0.
Screen output: NSLog (@ "hello"); NSLog (@ "age is % d", 2); // line feed
Iii. OC Program Development Process
# The import pre-processing command has two functions: (1) copying the file content, like # include (2) automatically preventing the file content from being repeatedly copied
Program compilation connection process:
Source file (. m) --- (compile) ----> target file (. 0) ----- (Link) ----> executable file (. out)
Foundation framework. It is an essential framework for developing OC, iOS, and Mac programs. To use the content of the entire framework, you can include the main header file of the framework. The main header file is the most important header file in a framework. The main header file name of each framework is the same as that of the framework.
That is: # import <Foundation/Foundation. h>
The running process is as follows:
(1) write the OC source file. m. c
(2) Compile the cc-c xx. m xxx. c file
(3) link to cc xx. o xxx. o-framework Foundation (-framework Foundation is not required if the Foundation framework is not used)
(4) Run./a. out
Iv. BOOL type
Int main ()
{
BOOL B = YES;
BOOL b1 = NO;
BOOL b2 = 1; // YES
BOOL b3 = 2; // NO
NSLog (@ "% I", B );
}
Nature:
Typedef signed char BOOL;
Typedef signed char BOOL
Macro definition:
# Define YES (BOOL) 1
# Define NO (BOOL) 0
Boolean output is generally used as an integer.