1. What are the basic data type 1 basic types?
Swift basic data types include integer and floating point type. The base type starts with an uppercase letter. Assigning a value to a type can only be assigned with a numeric value of the same type.
#import Foundation//var intValue = 3.14
2 What are the integral types?
Integral type is divided into signed integral type and unsigned integer type, and integral type can be separated by bit. There are several:
Int8, Int16, Int32, Int64
UInt8, UInt16, UInt32, UInt64
3 What are floating-point types?
Float type, double type
4 How do I use basic data types?
The following code describes how to use the base type.
#import Foundationvar intValue : Int = 8println(intValue)var doubleValue : Double = 8.8println(doubleValue)
5 What are the syntax for different types of conversion assignments?
Two types cannot use the implicit type conversion.
However, you can use forced type conversions. Note that parentheses are given to the variable, not to the type.
The syntax is as follows:
Type 1 Variable value = Type 2 (type 2 variable value)
#import Foundationvar0//var doubleValue = intValuevar doubleValue = Double(intValue)println(doubleValue)
2. How does the implicit type inference 1 work?
The variable type is implicitly set by the initial value of the variable by not writing the type label after the variable. The variable types in the following code are of type int and double type. In Swift, the integer default is the int value, and the float type defaults to the double value.
#import Foundationvar intValue = 0//等价于var intValue : Int = 0println(intValue)var doubleValue = 0.0//等价于var doubleValue : Double = 0.0println(doubleValue)var"swift"//等价于var stringValue : String = "swift"println(stringValue)
Swift Language-Basic data types