gpt4 book ai didi

arrays - 将 Array 作为参数传递给函数时出现“[String].Type”错误

转载 作者:行者123 更新时间:2023-11-28 05:59:50 24 4
gpt4 key购买 nike

长期阅读。尝试学习 Swift 的初学者的首次提问。这是一个完全菜鸟级的问题,但我一直没能找到答案,所以我提前为我自己的愚蠢和这个问题的简单性道歉。

我试图将数组传递给函数,但出现以下错误:无法将类型“[String]”的值转换为预期类型“[String]”

func confirmAndSend() {
startTitleInstructions.text = "confirm and send your survey"
confirmStackView.isHidden = false
populateConfirmStack(attributesChosen: [String])
}

func populateConfirmStack(attributesChosen: [String]) {
confirmLabel1.text = attributesChosen[0]
confirmLabel2.text = attributesChosen[1]
confirmLabel3.text = attributesChosen[2]
confirmLabel4.text = attributesChosen[3]
confirmLabel5.text = attributesChosen[4]
}

attributesChosen 参数被定义为一个空的 Array,类型为 String,它由用户最多选择五个选项来填充,即被附加到空的 Array。我在这一步中尝试做的是通过显示之前选择的五个选项来确认选择的属性。

我已经尝试了几种不同的方法来表达和构造它,遵循我在这里看到的其他 Int 示例,但没有任何方法对我有用。这看起来应该很容易,我猜这是一个明显的语法错误,其中一个错误我无法自行解决。

感谢您的帮助!

最佳答案

您正在发送 类型的数组,它应该是字符串值数组 ["a", "b"]

关于arrays - 将 Array 作为参数传递给函数时出现“[String].Type”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50142634/

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