Objective-C magic path [13-Preprocessing Program], objective-c13-

Source: Internet
Author: User

Objective-C magic path [13-Preprocessing Program], objective-c13-

Master haomeng is devoted to his contribution and respects the author's Labor achievements. Do not repost them.

If the article is helpful to you, you are welcome to donate to the author, support haomeng master, the amount of donation is free, focusing on your mind ^_^

I want to donate: Click to donate

Cocos2d-X source code download: point I send



Preprocessing provides some tools that make it easier to develop, read, and modify programs,

It is also easy to transplant programs to different systems.

You can also use the Preprocessing Program to customize the Objective-C language to adapt to the programming of a specific application or your own programming style.


The Preprocessing Program is part of the Objective-C compilation process and can identify specific statements distributed in the program.

The Preprocessing Program uses the # MARK. This sign must be the first non-space character in a line.


# Define statement:

# One of the basic purposes of the define statement is to specify a program constant for the symbol name.

The predefined name is not a variable. Therefore, it cannot be assigned a value unless the result of replacing the specified value is actually a variable.

# Define statements are often placed at the beginning of the program, but # After the import or include statements.

The predefined name and variable behavior are different: there is no such statement as a local definition.


All pre-defined names are in uppercase, which makes it easy to distinguish whether a name is a variable name, an object name, a class name, or a pre-defined name.


In fact, when a pre-defined name appears, the Preprocessing Program performs text replacement,

This explains why the # define statement cannot be ended by a semicolon.


Note: redefining the (# define AND &) behavior of the underlying language syntax is usually not a good programming habit,

It is not easy for others to understand your code.

If the second line is required, the last character in the previous line must be a backslash. \


Note: when defining a parameter name, spaces are not allowed before the left brackets of the predefined name and parameter list.

Parameters must be enclosed in parentheses.

# Define SQUARE (x )*(*))


# Import Statement:

The Preprocessing Program allows you to collect all definitions into a single file and then use the # import Statement to include them in the program.

This mainly distinguishes between "" and <>. "" Is a local path query, <> is a system path query.


Conditional compilation:

It is usually used to create programs that can be compiled and run on different computer systems. It is often used to switch various statements in the program.

# Ifdef, # endif, # else, # ifndef and # undef are the same as those in C.

# Ifdef DEBUG

# If defined (DEBUG)

The role is the same.

# Undef is used to remove the defined name



Use objective-c to compile a program to input any number and output the English letters of each control. However, a problem occurs.

Haha, it's you again. I forgot to write you the last question. Write it this time. Since you say You are learning oc, I will use oc to write. I can't remember the C language syntax clearly. You can simply copy the code written on the console. Don't forget to adopt it ~ Also, you must adopt the following questions ~~~

# Import <Foundation/Foundation. h>

Int main (int argc, const char * argv [])

{

@ Autoreleasepool {

Char str [1000]; // declare a char array, that is, a string

Scanf ("% s", str); // receives the content entered by the keyboard

NSString * oc_string = [NSString stringWithFormat: @ "% s", str]; // converts a string in C format to a string in OC format.

NSString * oc_tmp_str = oc_string; // copy the converted string

For (int I = 0; I <oc_string.length; I ++) {// create a loop. the maximum number of times is the string length.

Nsange range = {1, 2 };

NSString * str = [oc_tmp_str substringToIndex: range. location]; // obtain the first string and assign it to str.

Oc_tmp_str = [oc_tmp_str substringFromIndex: range. location]; // assign the second digit to oc_tmp_str and use it as the first part of the next loop. The loop ends.

Switch ([str intValue]) {

Case 0:

NSLog (@ "zero \ n ");

Break;

Case 1:

NSLog (@ "one \ n ");

Break;

Case 2:

NSLog (@ "two \ n ");

Break;

Case 3:

NSLog (@ "three \ n ");

Break;

Case 4:

NSLog (@ "four \ n ");

Break;

Case 5:

NSLog (@ "five \ n ");

Break;

... The remaining full text>

Objective-C20 programming is different from Objective-C Basics

Objective-c2.0 this book focuses on objective-C language, still count
The basic tutorial briefly introduces ob-c focuses on interface design, various interactions, and animation design.
We recommend that you first look at the program design. View and write interfaces.

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.