definition of Swift variable
1 Import Foundation2 3 /*4 definition of a variable5 The type of the variable can be used without writing6 var a=107 definition of constants let decoration8 */9 Ten varA=Ten One print (a) ALet b= One - print (b) - the /* - Type Callout - Specify the type of variable: [space] Capitalize first letter - */ + varX:int -x=9 + print (x) ALet y:int=Ten at print (y) - /* - Naming Conventions - specification for name without compound marker - */ - var_ttx=Ten in print (_TTX) - /* to basic type All data types are capitalized in the first letter + integer type, decimal type - Int Int8 Int16 Int32 Int64 the UInt uint8/16/32/64 Unsigned numeric type value cannot be negative * floating-point data $ double/floatPanax Notoginseng */ - varInterger:int32=Ten the print (Interger) + vart:float=2.123 A print (t) the vartt:double=2.12 + print (TT) -t=Float (TT) $ print (t) $ /* - type inference and type safety - assign an initial value when declaring a type the */ - varStr=""WuyiStr="string" the print (str) - //Type Conversions WuLet trueof:bool=true - iftrueof{ AboutPrint"true") $}Else{ -Print"false") - } - //Meta-group A varStudent= ("a",true,"C",Ten) +Print (student.0) the varstudents= (Name:"Liushiqun", Age:Ten, Address:"Beijing") - print (students.name) $ //Optional value Optional type the varoptvalue:int?= - the //! Represents a forced resolution of an optional value the //var svalue:int=optvalue! the - //print (svalue) in if(Optvalue! =Nil) { the print (Optvalue) the } About varStvalue=0 the the //Evaluation of the assignment of an optional value the if varS_tvalue =Optvalue { +Stvalue=S_tvalue - print (Stvalue) the }Bayi //implicitly resolves an optional type the varoptvalue1:int!=9 the if(Optvalue1! =Nil) { - print (optvalue1) - } the if varIvalue=optvalue1 { the print (ivalue) the } the varI_values:int=optvalue1 - print (i_values) theprintln"Hello")
The definition of a beginner Swift note variable (i.)