gpt4 book ai didi

ios - Swift - 如何查找数组中数组中项目的索引

转载 作者:行者123 更新时间:2023-11-30 11:52:19 26 4
gpt4 key购买 nike

我只有 10 岁,正在制作一款 war (纸牌游戏)应用程序。在 war 应用程序中,我必须将数组放入数组中。我如何在这种数组中找到项目的索引? 这是一个我会收到错误的示例:

var card_array = [["2_of_clubs", "2_of_diamonds", "2_of_hearts", "2_of_spades"],
["3_of_clubs", "3_of_diamonds", "3_of_hearts", "3_of_spades"],
["4_of_clubs", "4_of_diamonds", "4_of_hearts", "4_of_spades"],
["5_of_clubs", "5_of_diamonds", "5_of_hearts", "5_of_spades"],
["6_of_clubs", "6_of_diamonds", "6_of_hearts", "6_of_spades"],
["7_of_clubs", "7_of_diamonds", "7_of_hearts", "7_of_spades"],
["8_of_clubs", "8_of_diamonds", "8_of_hearts", "8_of_spades"],
["9_of_clubs", "9_of_diamonds", "9_of_hearts", "9_of_spades"],
["10_of_clubs", "10_of_diamonds", "10_of_hearts", "10_of_spades"],
["jack_of_clubs2", "jack_of_diamonds2", "jack_of_hearts2", "jack_of_spades2"],
["queen_of_clubs2", "queen_of_diamonds2", "queen_of_hearts2", "queen_of_spades2"],
["king_of_clubs2", "king_of_diamonds2", "king_of_hearts2", "king_of_spades2"],
["ace_of_clubs", "ace_of_diamonds", "ace_of_hearts", "ace_of_spades"]]
var locationBottom = card_array.index(of: ["4_of_spades"])
var locationTop = card_array.index(of: ["king_of_diamonds2"])
print(locationTop)
print(locationBottom)

最佳答案

看起来你想要的是:

var locationBottom = card_array[0].index(of: "4_of_spades")
var locationTop = card_array[0].index(of: "king_of_diamonds2")

相反,您正在寻找一个数组实例,该数组在包含所有 52 张卡片的数组中仅包含一张卡片。

关于ios - Swift - 如何查找数组中数组中项目的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48216497/

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