IOS review notes: Objective-C syntax Basics
I. Syntax Basics
1 keyword
The keywords basically start with @. Common keywords are as follows:
@ Interface, @ implement, @ end, @ public, @ private, @ selector, @ required, @ encode, etc.
Other IDs, self, super, etc.
2. the string starts @.
@ "Hello world! "
3 Boolean Yes/No
4. null type nil (value: 0)
5 other C language syntax
2 OC HelloWorld Program
// Helloworld. m # import
# Include
Int main () {printf ("OC fully compatible with C \ n"); NSLog (@ "Hello World"); // automatically wrap return 0 ;}
In Mac, cc is compiled using clang.
Compile:
cc -c helloworld.m
A hellowold. o will be generated under the current folder.
Link:
cc hellowork.o -framework Foundataion
A. out will be generated under the current folder.
Run:
./a.out
It will be printed on the screen:
Fully compatible with C
19:10:49. 451 a. out [503: 507] HelloWorld
3-plus files
// main.m#import "helloworld.h"int main(){ show(); return 0;}
# Import
# Include
// Helloworld. hvoid show () {printf ("OC fully compatible with C \ n"); NSLog (@ "HelloWorld ");}
Compile and generate the. o file:
cc -c main.m
Link generation a. out
cc main.o
The running mode and result are the same as above.