What is Swift?
Swift is a scripting language published by WWDC.
Benefits of using Swift: OC ARC The biggest difficult memory management
And Swift doesn't have to worry about memory. Simple, functional
Very powerful, simple syntax and OC language can call each other.
But there are weaknesses, not high security: H. m
two of Swift do not need: 1. No need to write the main function
2. There is no need to add a semicolon in the back, of course, plus yes (the same line has two lines of code, the middle must be added;)
Syntax: 1.let modifiers are constants, constants are not allowed to change variables such as let constant 1 = 2.var defined
A swift variable or a naming convention for constants
1. Cannot have mathematical symbols (e.g. + *)
2. Cannot contain arrows
3. Cannot have illegal invalid non-encoded characters.
4. Cannot have a keyword (let, var)
5, cannot contain horizontal lines, indicator (my--name)
6, cannot start with a number
7. Cannot have only one slide line alone. (var _)
Defining variables : 1. Implicit variables
var myVar1 = "Hello"//myvar1 he is a variable of type string
var num = num system defaults to a variable of type int
var num1 = 23.0 NUM1 system defaults to a double type of variable
2. Explicit variables
var myvar1:string = "Hello"
var num:double = 23.0
Data Conversion : The following:
Let number 1:int = 30
Let number 2:double = 23.5
Let number 3:double = number 1 + number 2
If this is defined, the number 3 is an error, because the number 1 is the int type.
The number 2 is Double. The Let number 3:double = number 1 + number 2 must be converted into
Let number 3:double = Double (number 1) + Number 2
And that's the right thing to do.
Let number 4 = 22+3.11
You can use the Typealias keyword to define the alias of the type, similar to the typedef of the C language
Typealias MyInt = Int
Let Sum:myint = 23
Tips for Swift syntax