Swift (i) base variable type

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.