Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何返回包含已搜索元素的元素_Arrays_Swift3 - Fatal编程技术网

Arrays 如何返回包含已搜索元素的元素

Arrays 如何返回包含已搜索元素的元素,arrays,swift3,Arrays,Swift3,我有两门课: - Favourite + key + showKey - Show + key 我有一系列最喜欢的节目[最喜欢的] 我有一个表演对象 要检查节目的关键点是否是FavoriteShows的一部分,请执行以下操作: if favouriteShows.contains(where: {$0.showKey == show.key}) { ... } 但我还想确定哪一个最受欢迎的游戏拥有showKey 类似于让FavoriteIndex=FavoriteS

我有两门课:

- Favourite
    + key
    + showKey
 - Show
    + key
我有一系列最喜欢的节目[最喜欢的] 我有一个表演对象

要检查节目的关键点是否是FavoriteShows的一部分,请执行以下操作:

if favouriteShows.contains(where: {$0.showKey == show.key}) {
...
}
但我还想确定哪一个最受欢迎的游戏拥有showKey

类似于让FavoriteIndex=FavoriteShows.containswhere:{$0.showKey==show.key}

您要查找的内容


或者,您可以按如下方式枚举FavoriteShows数组:

for (ndx, sh) in favouriteShows.enumerated() {
    if sh.showKey == show.key {
        // ndx contains the index at this point
    }
}
您甚至可以使用firstwhere:像这样获取对象
for (ndx, sh) in favouriteShows.enumerated() {
    if sh.showKey == show.key {
        // ndx contains the index at this point
    }
}