我有一个 Swift 字典,我正在尝试完全删除一个条目。我的代码如下:
import UIKit
var questions: [[String:Any]] = [
[
"question": "What is the capital of Alabama?",
"answer": "Montgomery"
],
[
"question": "What is the capital of Alaska?",
"answer": "Juneau"
]
]
var ask1 = questions[0]
var ask2 = ask1["question"]
print(ask2!) // What is the capital of Alabama?
questions[0].removeAll()
ask1 = questions[0] // [:]
ask2 = ask1["question"] // nil - Should be "What is the capital of Alaska?"
我使用 questions[0].removeAll() 删除条目,但它留下了一个空条目。我怎样才能完全删除一个条目以便没有痕迹?