Getting started with IOS development (1)-data types and operators, getting started with ios

Source: Internet
Author: User

Getting started with IOS development (1)-data types and operators, getting started with ios

OC syntax (1) Data Types and operators

1.1 annotations
Like other languages, annotations allow single-line and multi-line comments. Some formal comments are required in a standardized code, as shown in the following comments:
/*
This is multi-line
Note
*/
// This is a multi-line comment
The OC language currently does not support nested annotations. (Swift supports this feature)

1.2 identifier and variable

1.2.1 Separator
1. semicolon
Each sentence ends with a semicolon. One row can have multiple statements. One statement can also span multiple rows, but variable names cannot be separated.
Valid:
NSString * name = @ ""; int age = 20;
NSString * hello = [@ "well" stringByAppendingString:
@ "I am also good"];
Invalid:
NSString * my
Name = @ "James ";

2. curly braces
{} Appears in pairs, used in functions, if statements, switch statements, ect.
3. square brackets
Square brackets are used in arrays, dictionaries, and method calls.
For example:
Arr [2] = 2;
Dict [@ "id"] = 2;
NSString * string = @ "Haha ";
[Stirng length];
 
4. parentheses
Parameter transfer.
5. Space
Space. Word and Word Segmentation
6. Bullets
Variable calls
 
1.1.2 marking rules
The Object_C language identifier must start with an underscore (_) or a dollar sign. It can start with a letter, digit, underscore (_), or dollar sign.
1. The identifier is case sensitive.
2. The identifier cannot be a keyword, but it can contain a keyword.
3. The identifier cannot contain spaces
4. The identifier can only have the Dollar $ symbol, but cannot have other symbols

1.1.3 keywords
The keyword will display a specific color in Xcode. Common keywords are used here.
Auto break case char const continue default do double else enum
Extern float for goto if int long register return short signed sizeof
Static struct switch typedef union unsigned void volatile while
 
1.2 Basic Data Types
1.2.1. Integer
1.2.2.NSLog output format
D. output in a signed decimal format.
O octal symbol output
X hexadecimal unsigned output
U unsigned decimal output integer
C is output with only one character
S outputs a c-style string
F is output in decimal form. The default output is 6 digits.
E outputs a floating point number in the form of an index, and the number area outputs 6 digits by default.
G automatically selects % e or % f output, and does not output meaningless 0
P returns the address of the pointer in hexadecimal format.
@ Output object-c object

1.2.3. Optimized type
1. Common Sequence Types
\ B Return character
\ N linefeed
\ R carriage return
\ T Tab
\ "Double quotation marks
\ 'Single quotes
\ Backslash
2. Note: During Development in Xcode, escape characters must be used; otherwise, errors may occur.

1.2.4 floating point type
Floating Point Numbers include decimal and scientific calculation methods. Such as 12.34 and 5E2.
Note: If you use a floating point number divided by 0.0, positive infinity or negative infinity is obtained. If you use an integer divided by 0.0, the boundary value of the integer value range is obtained, for example, 10/0. 0 = 2147483647.
-3/0. 0 =-2147483647
1.2.5 Enumeration
Enumeration is often used in Object-c development.
Directly Add code
Enum animals {dog = 2, cat = 1, pig, cow, Baidu };
// Define an enumerated variable
Enum animals myCat, myDog;
MyCat = cat;
MyDog = dog;
NSLog (@ "% d and % d", myCat, dog) // output: 1 and 2

// Defines anonymous enumerated Variables
Enum {male, famale} me, you;
Me = male;
You = 1;

1.2.6 Boolean
The bottom layer of Object-C actually uses signed char to represent BOOL, while the two bottom layer values of YES and NO are 0 and 1.
The system header file is defined as follows:
Typedef signed char BOOL;
# If! Defined (YES)
# Define YES (BOOL) 1;
# Endif
# If! Defined (YES)
# Define NO (BOOL) 0;
# Endif
// You can assign a value to the BOOl type.
BOOL b1 = 1;
BOOL b2= 100;

// Error
BOOL b3 = 256; // This is incorrect. BOOL is an eight-bit signed char. It is out of bounds.

1.2.7 type conversion
Type conversion is like pouring water in the bottle to each other. It is basically okay to pour small water into large water. However, you need to be cautious when importing large data into small data. problems may occur.
Int intValue = 33000;
Short sort value = intValue;
// It must have exceeded.
Look at the overflow process (if you have never learned the computer composition principle, you may not understand it ...)
Learn more {
The original Code directly converts the value to binary, but the computer saves all integers in the form of a complement code. The rules for calculating the complement Code are as follows:
The positive complement code is the same as the original code. The negative complement code is its inverse code plus one. The reverse code is bitwise opposite to the original code, but the highest bit remains unchanged.

}
3000 original code
00000000000000001000000011101000
Truncation to short only keeps 16 bits
0000000000000000 1000000011101000 // The highest bit is 1, indicating a negative number
Subtract 1 to get the reverse code 1000000011100111.
Except the symbol bit, the other digits are reversed to obtain the original code.
Final complement: 1111111100011000

1.2.8 operator no. (This parameter is ignored after addition, subtraction, multiplication, division, and so on)
& Bitwise AND
| By bit or
~ Non-bitwise, reversed by bitwise
^ Bitwise OR
<Shift left by bit
> Shift right by bit
Note: Shifts n to the left is like multiplying the n power of 2, and shifts n to the right is dividing by the n power of 2 (if Division is not allowed, it is the maximum integer that returns the division result ),
The operations before bitwise operations will not change.







 

 


Getting started with IOS development

This must be recommended to you. You search for "ios Program Design" on the Internet. It is a set of lecture videos. There are 23 lessons in total, as long as you have a little experience in Class c language development, you will be able to learn it easily with an air conditioner blanket and headphones lying down. It took me two days to get started.

Is it good for beginners to get started with iOS 5 application development, or is it good for basic iOS 5 tutorials?

I am reading this basic iOS 5 tutorial. We recommend that you get started with the Stanford Old Man video.

Related Article

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.