"oc" Basic Syntax

Source: Internet
Author: User

I. INTRODUCTION of OC

On the basis of C language, a layer of minimal object-oriented syntax is added, fully compatible with C language, C language code can be mixed in OC code, or even C + + code, and you can use OC to develop applications for Mac OS x platform and iOS platform.

Second, OC Syntax Preview (i) keywords

Basically all the keywords are at the beginning of the @, such as @interface @implementation @public, and so on, a small part does not start with @, such as Id,_cmd

(b) The string begins with @

C-language string: "Hello"

OC language string: @ "Hello"

(iii) Other grammatical

Basic type: 5, added Boolean type bool (yes/no).

Nil equals null in C, which is 0.

Screen output: NSLog (@ "Hello"); NSLog (@ "Age is%d", 2); Wrap Line

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. is the development of OC, IOS, MAC program necessary framework, if you want to use the entire framework of content, including the framework of the main header file. 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.

namely: #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 (without using the foundation framework, you do not have to add-framework Foundation)

(4) run./a.out

Iv. type of bool

int main ()

{

BOOL B=yes;

BOOL B1=no;

BOOL b2=1;//YES

BOOL b3=2;//NO

NSLog (@ "%i", b);

}

Essence:

typedef signed Char BOOL;

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.

Reprint Address: http://www.cnblogs.com/xiaodong208/p/4232589.html

"oc" Basic Syntax

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.