Basic data TypesOc:
integer int intvalue = 10;
Floating-point double doublevalue = 10.10; float Floatvalue = 5.1;
Chang Long
Short
Signed signed
Unsigned unsigned the range of values for various types of data is different from the compiler for different bits. Swift: note keyword uppercase integer var intvalue:int = 10 floating-point var intvalue1:double = 10.10 means 64-bit floating-point Var Intvalue2:float = 9.9 means 32-bit floating-point number if the length is divided, the length of Swift is more accurate than oc var intvalue3:int8 = 6
var intvalue4:int16 = 7
var Intvalue5:int32 = 8var Intvalue6:int64 = 9 signed unsigned, default is signed (Uint8/uint16/uint32/uint64) var uintvalue7:uint = 10 Note: unsigned The number is greater than the signed value, because the symbol bit is also used to store the value Swift is a type-safe language, if the value error will be directly an incorrect, and OC will not take the value of oc:unsigned int intvalue =-10; No error Swift:var Intvalue:uint = 10 will error overflow: oc:int intvalue = Int_max + 1; No error Swift:var Intvalue:uint = Uint.max + 1 Error data type reciprocal assignment (implicit type conversion) OC can implicitly type convert int intvalue = 10;double Doublevalue = intvalue; Swift: No implicit type conversion in Swift "value is never implicitly converted to another type" (an implicit type conversion in OC) The following statement will error var intvalue:int = 10var doublevalue:double = intvalue
data type conversions Swift does not allow implicit type conversions, but can use display type conversions (coercion type conversions) OC notation int intvalue = 10;double Doublevalue = (double) intvalue; Swift notation: var intvalue:int = 10
var doublevalue:doubledoublevalue = double (intvalue) Note: double () does not modify the value of Intvalue Instead, it generates a temporary value assignment to Doublevalueprint (intvalue) print (doublevalue) by Intvalue value.
Swift Basic Syntax (02-Basic data type)