iOS Development Swift Chapter (01) Variables & Constants & Tuples
Description
1) Finally, write a swift. In fact, as early as 14 has been written in the swift part of the blog, but the passage of time, it is already different past. In addition, no corrections and updates are made to the blog post on the 14 part of the iOS development Swift feature.
2) The corresponding code for this blog post can be obtained in Https://github.com/HanGangAndHanMeimei/Code.
First, variables and constants
01 definitions of variables and constants
In swift, variables are decorated with Var, constants are decorated with let, variables can be modified and constants cannot be modified.
Variable: var
Constants: Let
Format: modifier (var|let) variable | constant name: data type = value
Note: In the use of swift development process, let is used in general, only when the data needs to be modified and then modified to Var, can guarantee data security.
02 Type Deduction
In Swift, if the variable | constant is initialized when it is defined, then the data type can be omitted and the data type of the variable | constant will be deduced automatically.
Recommendation: You should use automatic deduction whenever possible in development (unless you need to explicitly specify the length of the data or need to define a post-initialization), you can minimize the redundancy of the code.
03 Type Conversions
There are display conversions and implicit type conversions in OC, but there is no implicit type conversion in swift, only data of the same type can be assigned or evaluated.
Two, the meta-group
A tuple is a composite data type that is referred to as a tuple whenever multiple data (which can be of the same or different data types) is used overnight ().
The advantage of tuples is that it is convenient to implement functions that return multiple values.
Tuple definition Format: constant | variable modifier constant | Name of variable: (data type 1, data type 2, data type 3) = (value 1, value 2, value 3)
iOS Development Swift Chapter (01) Variables & Constants & Tuples