title: How to filter an array containing a string and an array of structure objects, in which there is a string parameter?
body: <p>I have an array</p>
  
  <pre><code>var friendsListGroupedFiltered = [Object]()
  </code></pre>
  
  <p>of this structure</p>
  
  <pre><code>struct Object {
      var letters : String
      var sectionObjects : [Friend]
  }
  </code></pre>
  
  <p>that contains an array of objects of another structure</p>
  
  <pre><code>struct Friend {
      let name: String
      let image: UIImage?
      let likes: Int
      let isLiked: Bool
  }
  extension Friend: Equatable {
      static func == (lhs: Friend, rhs: Friend) -&gt; Bool {
          return lhs.name == rhs.name
      }
  }
  </code></pre>
  
  <p>And to be precise, I want to make a filter function for searchbar.
  I tried like this</p>
  
  <pre><code>func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
      guard !searchText.isEmpty else {
          friendsListGroupedFiltered = friendsListGrouped
          tableView.reloadData()
          return
      }
      friendsListGroupedFiltered = friendsListGroupedFiltered.filter {
          $0.sectionObjects.filter {
              $0.name.range (of: searchText, options: .caseInsensitive) != nil
          }
      }
      tableView.reloadData()
  }
  </code></pre>
  
  <p>and get an error</p>
  
  <blockquote>
    <p>Cannot convert value of type '[Friend]' to closure result type 'Bool'</p>
  </blockquote>
  
  <p>array friendsListGroupedFiltered looks something like this</p>
  
  <pre><code>[Object(
      letters: "А",
      sectionObjects: [
          Friend(name: "Августин", image: Optional(&lt;UIImage: 0x600000d3ab50&gt;, {200, 200}), likes: 20, isLiked: false),
          Friend(name: "Акакий", image: Optional(&lt;UIImage: 0x600000d3ab50&gt;, {200, 200}), likes: 20, isLiked: false),
          Friend(name: "Алёша", image: Optional(&lt;UIImage: 0x600000d3ab50&gt;, {200, 200}), likes: 20, isLiked: false),
          Friend(name: "Армэн", image: Optional(&lt;UIImage: 0x600000d3ab50&gt;, {200, 200}), likes: 20, isLiked: false)
      ]
  ),
  Object(
      letters: "В",
      sectionObjects: [
          Friend(name: "Вася", image: Optional(&lt;UIImage: 0x600000d3ab50&gt;, {200, 200}), likes: 20, isLiked: false)
      ]
  ),
  Object(
      letters: "К",
      sectionObjects: [
          Friend(name: "Коловрат", image: Optional(&lt;UIImage: 0x600000d3ab50&gt;, {200, 200}), likes: 20, isLiked: false)
      ]
  )
  </code></pre>
  
  <p>etc<br>
  How can I sort an array by 'name' that is contained within another array of objects of another structure?</p>