title: Filter nested list class in core data by swift
body: <p>I want to filter a nested class and show it in table view by search. My classes are:</p>
  
  <pre><code>class group {
   var name: String?
   var words: [word]?
  
  }
  
  class word {
   var text: String?
  }
  </code></pre>
  
  <p>I have this object for searching the following code:</p>
  
  <pre><code>var groups: [group] = { ... }
  var filterdGroups: [group]?
  </code></pre>
  
  <p>I want to search a word in the <code>groups[...].words</code> and show it in <code>UITableView</code> like:</p>
  
  <ul>
  <li><p>group 1 (section*)</p>
  
  <ul>
  <li>word1 (cell)</li>
  <li>word2 (cell)</li>
  <li>word3 (cell)</li>
  </ul></li>
  <li><p>group 1 (section*)</p>
  
  <ul>
  <li>word12 (cell)</li>
  <li>word24 (cell)</li>
  <li>word35 (cell)</li>
  </ul></li>
  <li><p>[...]
  As you see <code>group.name</code> is the <code>section name</code> and <code>word.text</code> is the <code>cell</code> in <code>UITableView</code>. I want to find an optimized way to filter <code>words</code> of each <code>group</code> like the following code:</p>
  
  <pre><code>{ ...
    for group in groups {
     guard var wordList = group.words else {
       retun
      }
       wordList.filter((word) -&gt; Bool in 
             return word.text.contains(searchText)
            )
        // ???? How can I give it to `group` and filter `group`
  
   }
    ... }
  </code></pre></li>
  </ul>
  
  <p>The problem is group is a class in core data so I can't make a new object of it and I don't want to put all of them in new object model as it's not optimized.</p>