gpt4 book ai didi

ios - swift - if 语句和数组

转载 作者:行者123 更新时间:2023-11-30 11:23:45 24 4
gpt4 key购买 nike

我想将 DicX 中的字符串与现有标题(根据单元格选择而变化的表格标题)进行匹配。

var DicX = ["xx",
"yy",
"zz",
"qq"]

let DicYY = [["11", "22", "33", "44"],
["1", "2", "3", "4"],
["m", "n", "k", "b"],
["bb", "kk", "mm", "nn"]]

我要比较的标题是这样的:

title = detailX.insideTitle

所以我希望当标题字符串等于 DicX 字符串之一时,在按钮上的 4 个字符串中的每一个中显示 DicYY 中对应的字符串。

但无法正确匹配,我尝试这样做:

var currentX = detailX.insideTitle
if DicX == currentX["DicX"] {
}

我收到此消息:

Cannot subscript a value of type 'String' with an index of type 'String'

如何执行 if 语句?如何从 DicYY 中获取对应的内容?

最佳答案

这可以完成工作(如果我做对了)。

import Foundation

let DicX = ["xx",
"yy",
"zz",
"qq"]

let DicYY = [["11", "22", "33", "44"],
["1", "2", "3", "4"],
["m", "n", "k", "b"],
["bb", "kk", "mm", "nn"]]

let searchterm = "yy"

for (index, elem) in DicX.enumerated()
{
if (searchterm != elem) { continue }
print(DicYY[index]) // This will print ["1","2","3","4"]
}

关于ios - swift - if 语句和数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50986070/

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