This tutorial is a summary of the author's self-taught ios/swift knowledge, which applies to the application of objictive C programming and the need to understand the iOS program-based iphone and ipad programmer. Be a bigger ' siege lion ', work with dignity, work happily, enjoy work.
A Grammar notice
- The source file name extension for Swift is. Swift.
The source file name extensions for OBJECT-C are. h and. M.
1) You do not need to write the main function
Execute the code sequentially from the top down, so the first code is automatically used as the entry for the program.
2) You do not need to add a semicolon after each statement
10
If you want, each code statement can also be added;
let radius = 10;
There is a case where the code statement must be appended with '; ' (semicolon): when there are more than one statement on the same line of code
1) Single-line comment
// This is a single-line comment
2) Multi-line Comment
/* This is a multiline comment, which is a multiline comment. */
3) Multilayer annotations can nest multiple lines of comments
/* Outer comment/* Inner comment */ */
1) How to declare constants and variables
Declare constants with Let
10
declaring variables with Var
- var x=0.0 , y=0.00.0
Two first Swift programs
Example: The classic code for any development language, print out the Helloword in the console.
Import foundationprintln ("Hello, world! ")
If you are printing Helloword in the Java language, the code is as follows.
class firstclass{ publicstaticvoid main (string[] args) { System. out. println ("Hello, world! " ); } }
Three PlayGround
Swift Development Learning-02 variables and constants