我正在尝试在字典中查找条目的索引。我的字典如下:
// Dictionary
var questions: [[String:Any]] = [
[
"quesID": 1000,
"question": "What is the capital of Alabama?",
"answer": "Montgomery",
],
[
"quesID": 1001,
"question": "What is the capital of Alaska?",
"answer": "Juneau",
]
]
我尝试使用 indexOf 但它不起作用。我的代码如下:
// Find index of dictionary entry with quesID of 1000
let indexOfA = questions.indexOf(1000) // Should return 0
// Find index of dictionary entry with quesID of 1001
let indexOfB = questions.indexOf(1001) // Should return 1