I. introduction of OC
1. based on the C language, a minimal object-oriented syntax is added
2. fully compatible with C language
3. You can mix C language code in OC code , even C + + code
4. applications that can use OC to develop Mac platforms and IOS platforms
Second,OC Common grammar
1. Keywords
* basically all keywords start with @
@interface , @implementation , Span style= "color: #0000ff;" > @end @public , @protected , @private , @selector @try , @catch , @throw , @finally @protocol , @optional, @required, @class @property, @synthesize , @dynamicself, Super, id , _cmd, __block, __strong, __weak,
2. strings are preceded by @
@ "Hello" is a string in OC, while "Hello" is a string in the C language
3. Other Syntax
Third, the development process of OC program
Four, the first OC program
1. Code writing
#import <Foundation/Foundation.h>int main () { NSLog (@ " 2nd OC Program "); return 0 ;}
2. Terminal Instructions
* compile cc-c code . M // code here . M for files with the extension. m
* link cc code . O-framework Foundation
* run . /A. Out
3. The difference between NSLog and printf
* NSLog receives OC string as parameter,printf receives C language string as parameter
* NSLog will be wrapped after output and will not be wrapped automatically after printf output .
* #import <Foundation/Foundation.h> required to use NSLog
* using printf requires #include <stdio.h>
4. The role of #import
* like #include , used to copy the contents of a file
* can automatically prevent the file content to be copied multiple times, it means that the header file is not included in the following preprocessing instructions
#ifndef _stdio_h_ #define _stdio_h_#endif
5. Role of the Foundation framework
* Develop The necessary framework for OC, IOS and MAC programs
* This framework contains a number of commonly used APIs(application programming interfaces)
* The framework contains a lot of header files, if you want to use the contents of the entire framework, including its main header file can be
#import <Foundation/Foundation.h>
6. use of BOOL
* variables of type BOOL have 2 values:YES,NO
#define YES (BOOL) 1#define NO (bool) 0
* output of BOOL (as integer )
NSLog (@ "%d%d", YES, NO);
01-First Knowledge OC