gpt4 book ai didi

ios - Int 不可转换为 Dictionary

转载 作者:行者123 更新时间:2023-11-28 06:48:16 28 4
gpt4 key购买 nike

此行有错误 (questionField.text = listOfQuestionsAndAnswers[currentQuestionIndex])(Int 不可转换为 Dictionary)。而且,我希望所有的问题都一一显示,在最后一个问题之后,“Who's is Paul”应该再次显示......

let listOfQuestionsAndAnswers = ["Who’s Paul?": "An American", "Who’s Joao?": "A Bresilian", "Who’s Riccardo?": "An Italian"]

@IBAction func answerButtonTapped (sender: AnyObject){

for (Question, rightAnswer) in listOfQuestionsAndAnswers {

questionField.text = listOfQuestionsAndAnswers[currentQuestionIndex]
if currentQuestionIndex <= listOfQuestionsAndAnswers.count
{
currentQuestionIndex = (++currentQuestionIndex) % listOfQuestionsAndAnswers.count
answerBut.setTitle("ANSWER", forState: UIControlState.Normal)
}
else
{
(sender as UIButton).userInteractionEnabled = false
}
}
}

我收到错误 Int is not convertible to DictionaryIndex 并且我不明白这是什么意思。我不应该能够通过索引访问我的词典吗?

最佳答案

你不能用 Int 给字典下标。字典包含键和值,并以键为下标。在这种情况下,您的 listOfQuestionsAndAnswers 是一个字典,其中的键和值都是字符串。

如果您想使用 Int 下标,请考虑使用 (String, String) 元组数组。

如果你想使用字典,你必须通过它的键从字典中检索值:

listOfQuestionsAndAnswers["Who’s Paul?"] // "An American"

关于ios - Int 不可转换为 Dictionary<string, string>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35638608/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com