Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter array of tuples in swift

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)

But I've this error:

Anonymous closure argument not contained in a closure.

Any suggestion ?

like image 897
Jean Lebrument Avatar asked Nov 30 '25 03:11

Jean Lebrument


1 Answers

A closure must be defined between brackets:

var found = sectionsData.filter({$0.sectionName == myString})
// or equivalently
var found = sectionsData.filter {$0.sectionName == myString}
like image 169
Jean Logeart Avatar answered Dec 09 '25 00:12

Jean Logeart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!