入门 Swift 第三章

字符串插值

可以在字符串中插入表达式

1
2
3
4
let num = 3
let times = 3

print("\(num) 乘以 \(times)\(num * times)")

遍历个字典看看

1
2
3
4
5
6
7
8
9
let list = [
"Bill Gates": "Microsoft",
"Steve Jobs": "Apple",
"Lawrence Edward Larry Page": "Google"
]

for item in list {
print(item)
}
1
2
3
(key: "Steve Jobs", value: "Apple")
(key: "Lawrence Edward Larry Page", value: "Google")
(key: "Bill Gates", value: "Microsoft")

1
2
3
4
5
6
7
8
9
10
11
12
13
let list = [
"Bill Gates": "Microsoft",
"Steve Jobs": "Apple",
"Lawrence Edward Larry Page": "Google"
]

for item in list {
if item.key == "Steve Jobs" {
print(item.key, item.value)
} else {
print(item.value, item.key)
}
}
1
2
3
Microsoft Bill Gates
Steve Jobs Apple
Google Lawrence Edward Larry Page

看起来不错