0
class ListViewController: UITableViewController, UISearchResultsUpdating {

    var list = [MovieVO]()
    var filteredlist = [MovieVO]()
    var resultSearchController = UISearchController()

func updateSearchResultsForSearchController(searchController: UISearchController)
{
    self.filteredlist.removeAll(keepCapacity: false)

     let searchPredicate = NSPredicate(format: "title CONTAINS[c] %@", searchController.searchBar.text!)
     let array = (self.list as NSArray).filteredArrayUsingPredicate(searchPredicate)


     self.filteredlist = array as! [String] => Cannot assign a value of type '[String]' to a value of type '[MovieVO]'

    self.tableView.reloadData()
}
zaph
  • 111,848
  • 21
  • 189
  • 228

2 Answers2

1

You have defined self.filteredlist as a Swift array of MovieVO types, so no, you cannot assign to it an array of String types. Try and cast it to a MovieVO type or otherwise convert it to that type (perhaps it would be useful to see your definition of MovieVO).

Eppilo
  • 763
  • 6
  • 19
1

You've declared filteredlist as an array of MovieVO when you did:

var filteredlist = [MovieVO]()

So it can't accept [String], only [MovieVO].

I guess instead of casting your NSArray to [String] you wanted to cast it back to [MovieVO]:

self.filteredlist = array as! [MovieVO]

And to avoid crashes, replace this forced cast with optional binding:

if let movies = array as? [MovieVO] {
    self.filteredlist = movies
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253