Swift Language Fundamentals
Create a Workspace workspace, Project put workspace inside
Constants and variables for 1.Swift languages
① variable: var a=1,a=10 can also be modified after setting a variable var b=2
② constants are specified with Let, such as: let C =a+b
Once you assign a value to C, you can't adjust the value
The difference between a constant and a variable:
① variable can be arbitrarily changed after assignment
② constants usually cannot be changed after assignment, otherwise they will be error-
2.Swift Language data types
Indicate type: var s:string = "World" var i:int=1==
var words:string= "Southit"
In general, for the convenience of writing, not to specify the type, there is a fully automatic type of inference
3.Swift Language String Connection
var str= "Hello"
STR =str+ "Nanfangit"
printf (str)->result is: Hello Nanfangit
var i=200,var str = "Hello"
STR =str+ "World" str= "\ (str), asdef,\ (i)"//reference to a previously written variable
PrintIng (str)->result for Hello world,adef,200 string connection mode
4.swift language Arrays
① declares an array: var arr =["Hello,world", 100,2.3] can be written as any type
② declares an empty array: var arr=[],var arr2=string[] () means that there is an empty array that can only hold a specific type
5. Language Dictionaries
Dictionary equivalent to the map in C + +
such as: Var dictionary=["name:" "Sophia", "Age": "->result[name:sophia,age:18"
② dictionaries can also be dynamically assigned
dict["Sex"]= "Female"->[sex:female,name:sophia,age:18]
③ can take the characteristic position value by key
Printin (dict["name"])
The swift programming language for IOS