First, play a play playground
First of all, to create a new playground, after the creation, you will see a defined variable str in the program, in the right side of the sidebar will show the value of the variable, that is, we can in the process of programming the variable real-time monitoring.
1. Click the circle icon for the row in the right column, and the value of the variable will be displayed below the line of code.
2. Click the eye icon for the row in the right column to see the value of the variable
Have you ever felt that playground is fun? Try it yourself??????!
Ii. Introduction to Swift
1.Swift Overview
a). In July 2011, Chris Lattner began to dominate the development of the SWIFT programming language
b). In 2014, Apple unveiled Swift at the WWDC (Apple Developer Conference)
c). December 4, 2015, Swift official open source
D). Swift is primarily used for iOS and OS X application development
2.Swift Features
a). Simple and convenient, Swift combines the advantages of objective-c, JavaScript, Python and many other programming languages
b). Process interaction, you can monitor variables during programming by playground
c). Good safety
D). Efficient and powerful
Iii. Introduction to Swift
1. The code in the global scope automatically acts as the entry for the program, so the main function is not required.
2. Each statement after the '; ' can be added without adding, but in a row to write multiple independent statements, the statement must be separated by a semicolon.
The 3.print () output function comes with line breaks. In Xcode6, the println () output function comes with line breaks, and the print () output function does not have a newline, and the new version of Xcode's println () output function has been banned.
4. Basic data types: int integer, Double and float for floating point, bool Boolean, String literal type, array, Dictionary dictionary.
5. Declare a constant with let, and declare the variable with var. If you assign an initial value when declaring a variable, implicit type labeling is automatically performed.
1 - 2 var - 3 $ 4 var 3 4 5 // declare multiple variables separated by commas in a row
6. Type Callout
1 var name:string 2 " xiaoming " 3 print (name) 4 var real:double 5 3 6 print (real) // Real is a double type, so the printing result is 3.0
7. Naming rules: can contain letters, numbers, underscores, kanji, and emoticons, but cannot contain mathematical symbols, arrows, lines and tabs, and cannot start with a number
1 " Atlas " 2 Print (_ Hello 666) 3 var " That 's a good play. " 4 print (ABC?? _ My)
8. String interpolation
1 //mode one: \ (the variable or constant to insert)2 varApples =33 varOranges =34Print"I have \ (apples + oranges) fruits")5 //mode two: + String (the variable or constant to insert)6 vars ="1 + 1 ="7 varnum =28Print (s + String (num))
9. Note: Multi-line annotations can be nested
1 /* First Layer Comment 2 / * Second level comment 3 */ 4 */
Note: All content in this article is based on Xcode7.2, if there is inaccurate content, please understand! (2016-01-17)
Swift Self-study note--lesson01: Play a game of playground, Swift introduction and Getting Started