Import foundationprintln ("Hello, world!.")/*int A;*/var a=Ten //Implicit type conversionsA =9println (a) Let B=Tenprintln (b)/*Type Callout*///var x:int//x = 10.3 does not support implicit conversionsLet x:int=Ten/*names are not used in compliance with the specification of identifiers*/Let constant=Ten/*basic Data type: integer type, small tree encyclopedia int8/16/32/64uint8/16/32/64*/Let interger:int=TenLet unsignedint:uint32= +//Let overvalue:uint8 = Uint8.max/*two basic types can be implicitly converted*/var intvar:int=Ten/*type inference and type safety*/Let stringvalue="Hello"var uint8value:uint8=9var uint16value:uint16=9var uint32value:uint32= UInt32 (Uint8value) +uint32 (Uint16value)//Type Conversions/*type conversions, (type) expressions*///Let floatvalue:double = 1231323var floatvalue:double =1231323Intvar=Int (Floatvalue) println (intvar) Floatvalue=Double (Intvar)/*Boolean type*/Let turnofflight=1ifturnofflight==1{println ("Turn OFF")}Else{println ("Turn on")}/*tuple: (+, "hello")*/Let student: (string,int,double)= ("Zhangsan", at,98.5) println (student.0) println (student.1) println (student.2) Let (name,age,_)=studentprintln (name) println (age)//println (Score)Let student1= (Name:"Zhangsan", Age: at) println (student1.name) println (student1.age)/*Selectable values: Optionals, two states: value, no value*/var optvalue:int? =Nilif(Optvalue! =Nil) {println (optvalue)}//represents a forced resolution of optional values, optional values! //var svalue:int = optvalue!//Optional Bindingsifvar svalue =optvalue{println (svalue)}/*implicitly resolves optional types, two states, with values, no paper nil*/var imoptvalue:int! =8if(Imoptvalue! =Nil) {println (imoptvalue)}ifLet Ivalue =imoptvalue{println (ivalue)}var ivalue:int= Imoptvalue
Swift (i) base variable type