← 返回 snapchat 的题目列表Order of Execution in Swift with DispatchQueue
类型:online_judge
What is the order of output for the code below? Why does str += "3" result in 123 instead of 13 when a string is a value type?
var str = "1"
DispatchQueue.main.async {
str += "2"
print(str) // 12
}
DispatchQueue.main.async {
str += "3"
print(str) // 123
}
print(str) // 1
Example
Input
initial str: "1", async modification
Output
1\n12\n123