//: Playground-noun:a Place where people can play//concise way to include the frame, write the frame name directlyImport UIKit//var str = "Hello, playground"//println ();//Use this function in swift1.0 to printPrint"Hello World")//swift2.0 Printing Method//1. The difference from OC/*/ * (1) The statement does not need to add, (2) Comments can be nested, that is, multiple lines of comments can now be added to multiple lines of comments*/*///if more than one statement is written on the same line, the semicolon cannot omitvarsum =0;varA =1//if (sum = a) {// //}//2. Variables and Constantsvarb =2Let c=5 //constant is a quantity that cannot be modified, can only be initialized and cannot be assigned a value//Let C = 3//B = 7//C =//Swift automatically infers the type of the variable or constant based on the initial value-type deductionvarE =5.6varstr ="Hello"//implicit type deduction is used by default, and you can explicitly specify the data type of the variable-type annotationvarf:intf=TenPrint ("F = \ (f)")//formatted output//printf ("f=%d", f)//3. Naming rules for identifiers//almost all characters, allowing Chinese, even emoji can be used as an identifier in SwiftvarHeight = theprint (height)var?? ="Spit Tongue"print (??)//cannot contain mathematical symbols, arrows,-, tab, invalid Unicode//var w-2//cannot start with a number//Let 1wq = One//Unicode encoding//\u{n}, n can be any 1-8-bit hexadecimal numberLet Dollarstr ="\u{24}"Let Blackheart="\u{2665}"Let Redheart="\u{1f496}"//4. Data typevarK:int8 = -print (Int8.max) print (int8.min) print (Uint.max) print (uint.min)//The representation of integral type datavarnum = -varBnum = 0b1001// BinaryvarOnum = 0o21//octalvarXnum =0x11 //hexadecimal//floating Point TypeLet number =200.2 //default to double typeLet floatnumber:float =999.34//Scientific Counting MethodvarArea =1.25e-3varAREA2 = 0XFP2//15*2^2varAREA3 =0xC.3p0//(12*16^0+3*16^-1) *2^0//character type "single character"varg ="C" //String TypevarG2:character ="!" //Character Type//Stitching of characters//(1) interpolation symbol quick stitchingLet Fullg ="\ (g) \ (G2)"//(2) Turn the character Mr. Foo into a string and use the function of the string to stitchvarGstr = String (G2)//constructor Functiongstr.append (G2) gstr.appendcontentsof (g)//stringLet str2 ="a"varMystring:string ="Hello"//determine if a string is emptyStr2.isempty//operator overloading: Assigning a special meaning to +, representing the concatenation of stringsvarSTR3 = str +str2print (STR3)//5. Definition of type aliasesTypealias eightbits =UInt8//typedef UInt8 EightbitsvarReg:eightbits =1//6. Type conversionvarD1:int = AvarD2:double =34.5//Two variables of different types cannot be converted directly//D1 = D2//d2 = D1//Forcing type conversionsD1 =Int (D2) D2=Double (D1) let D3= -/5.0 //Implicit type conversions
Swift Basic data Type _01_var_let