0%

Swift 集合

数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
93> let color = ["red","orange","yellow","green"]
color: [String] = 4 values {
[0] = "red"
[1] = "orange"
[2] = "yellow"
[3] = "green"
}
94> color[0]
$R36: String = "red"
95> color[1]
$R37: String = "orange"
96> color[2]
$R38: String = "yellow"
97> color[3]
$R39: String = "green"

字典

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
126> var dict = ["name":"hello", "age":"10", "sex":"Female"]
dict: [String : String] = 3 key/value pairs {
[0] = {
key = "name"
value = "hello"
}
[1] = {
key = "age"
value = "10"
}
[2] = {
key = "sex"
value = "Female"
}
}

数组的数组

1
var array [String : [String]]

创建空数组

1
2
3
4
142> var empty_array : Array<Int> = []
empty_array: [Int] = 0 values
143> var empty_array = [Int]()
empty_array: [Int] = 0 values

创建空字典

1
2
151> var empty_dictionary = Dictionary<String,Double>()
empty_dictionary: [String : Double] = 0 key/value pairs
处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!

欢迎关注我的其它发布渠道