Filtering a 2D array with objects in Swift
<p>I have create the following struct to display a tableview:   </p>

<pre><code>struct Section {    
    var heading : String
    var items : [MusicModel]   
    init(category: String, objects : [MusicModel]) {        
       heading = category
       items = objects
   }
}
</code></pre>

<p>Then I have the following function to add objects to the array:</p>

<pre><code>var sectionsArray = [Section]()

func getSectionsFromData() -&gt; [Section] {
    let basicStrokes = Section(category: "Basic Strokes",
    objects: [MusicModel(title: Title.EightOnAHand, author: .None, snare: true, tenor: true)])

    sectionsArray.append(basicStrokes)
    return sectionsArray
}
</code></pre>

<p>So the tableview loads just fine with section header and rows for the data. I want to be able to filter the table cells but am having a tough time figuring out the proper syntax to filter an array of objects based on a user selected instrument that is sent to a filtering function. Here is what I have:</p>

<pre><code>func getMusic(instrument: MusicData.Instrument) -&gt; [Section] {
    if instrument == .Tenor {
        let filtered = sections.filter {$0.items.filter {$0.tenor == true}}
        return filtered
    } else {
        let filtered = sections.filter {$0.items.filter {$0.snare == true}}
        return filtered
    }
}
</code></pre>

<p>The object is returned only if snare or tenor is true. The error that I am getting is:
Cannot invoke 'filter' with an argument list of type '(@noescape (MusicModel) throws -> Bool)'</p>

<p>Any idea? If you have a suggestion on better way to do this I would greatly appreciate it. Thanks!</p>