快速过滤元组数组 [英] Filter array of tuples in swift

查看:62
本文介绍了快速过滤元组数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命名元组数组.

I have an array of named tuples.

我想根据元组数组的元素值在此数组上应用过滤器

And I would like to apply a filter on this array depending the value of an element of my array of tuples

typealias Section = (sectionName : String, sectionInputs : [Input])

var defaultSectionsData : [Section]

var found = sectionsData.filter($0.sectionName == myString)

但是我有这个错误:

闭包中不包含匿名闭包参数.

Anonymous closure argument not contained in a closure.

有什么建议吗?

推荐答案

必须在方括号之间定义闭包:

A closure must be defined between brackets:

var found = sectionsData.filter({$0.sectionName == myString})
// or equivalently
var found = sectionsData.filter {$0.sectionName == myString}

这篇关于快速过滤元组数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆