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()
}
Asked
Active
Viewed 1,373 times
0

zaph
- 111,848
- 21
- 189
- 228

Kwak Teddy
- 1
- 3
2 Answers
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
-
can you write solved code on here? i am sorry. i don't understand your reply. please help me. – Kwak Teddy Nov 17 '15 at 19:35
-
There's nothing to add, the fixed code is already in my answer. Read it carefully. :) – Eric Aya Nov 17 '15 at 19:42