Variables and constants:
If you want to define a variable equal to 1, just write var = 1,swift will automatically make type inference.
If you want to define a constant pi equal to 3.14, just write let PI = 3.14, constants can only be assigned once.
Output statement:
You can use the printf function directly to output an arbitrary type of information:
Prinft ("Hello Swift");
String Connection:
If all two variables are strings, you can connect directly with the + sign:
" Hello " var word " Word " = Hello + Word
If you want to connect the value of the other types of sea oil, then directly using \ () includes the connection can be made:
1 " Hello " 2 - 3 " \ (hello) \ (num) "
Cycle:
Traditional C-language loops:
for (int i =1;i<; i++) { //TODO}
In Swift:
1 inch 0.. <{2 //TODO3 }
Condition Judgment:
As with the C language, there is no difference.
In the swift language, the Swith...case statement can be used without the break keyword.
Function:
If you want to define a function to output a piece of information:
func SayHello () { printf ("Hello Swift");}
Object-oriented:
Definition of the class:
1 class hello{2 func SayHello () {3 printf ("Hello Swift "); 4 }5 }
The change example defines a class named Hello, in which there is a crown function called SayHello.
Call Function:
1 var h = Hello (); 2 H.sayhello ()
Inheritance of the class:
1 calss hi:hello{2 }
I'm a black horse-----swift Basic syntax