01-First Knowledge OC

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.