title: How can I sort a class using an array? - swift 5
body: <p>I've a class called "cars":</p>
  
  <pre><code>car1 = [name: "ferrari", color: "black", size: "small" ]
  car2 = [name: "Lamborghini", color: "orange", size: "small" ]
  car3 = [name: "Audi", color: "black", size: "big" ]
  car4 = [name: "fiat", color: "yellow", size: "small" ]
  car5 = [name: "ferrari", color: "red", size: "medium" ]
  </code></pre>
  
  <p>and made a list of them:</p>
  
  <pre><code>list = [car1,car2,car3,car4]
  </code></pre>
  
  <p>and now I want to sort/filter this list.</p>
  
  <p>If I try filtering it using a string, everything works fine:</p>
  
  <pre><code>let searchtext = "Audi"
  filteredlist = list.filter({ $0.name.lowercased().contains(searchText.lowercased()) })
        --&gt; filteredlist = [car3]   //result 
  </code></pre>
  
  <p>but I want to use an array, so them I could have more results shown. Something like filtering by  more than one color (similar to an "or" condition in an "if statement").</p>
  
  <p>I've tried the same struct (but of course didn't work):</p>
  
  <pre><code>let searchtext = ["black","red"]
  filteredlist = list.filter({ $0.color.contains(searchText) })
      --&gt; filteredlist = [car1,car3,car5]  //expected, got compilation error instead
  </code></pre>
  
  <p>I'm having these errors: </p>
  
  <pre><code>Cannot convert value of type 'String.Element' (aka 'Character') to expected argument type 'String'  
  Instance method 'contains' requires that '[String]' conform to 'StringProtocol'
  </code></pre>
  
  <p>I can think in 2 solutions (that aren't the ideal ones) to solve this need:</p>
  
  <p>1 - create a while/for function and filter the list for each element of the searchtext array and unite everything in the end (not recommended because I will have to read the list 'n' times )</p>
  
  <p><strong>update:stupid way</strong></p>
  
  <pre><code>var i = 0
  var listapp: [Item] = []
  while i &lt; searchtext.count {
      listapp.append(contentsOf: list.filter({ $0.tipo.contains(searchtext[i]) }))
      i += 1
  }
  list = listapp
  </code></pre>
  
  <p>2 - manually filtering the list using 'if','or','while' instead of using list.filter function</p>