I'm using Swift to create an iOS app, and I have a function that gets a list of all files in your documents directory and puts them in an NSMutableArray.
I'm searching on how to use a SearchBar to filter the items in a table view.
Is it possible to either put all items in an NSMutableArray into a regular array for me to use for this, or is it possible to modify the code below to work with an NSMutableArray
The tutorial:
var data = ["San Francisco","New York","San Jose","Chicago","Los Angeles","Austin","Seattle"]
var filtered:[String] = []
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
filtered = data.filter({ (text) -> Bool in
let tmp: NSString = text
let range = tmp.rangeOfString(searchText, options: NSStringCompareOptions.CaseInsensitiveSearch)
return range.location != NSNotFound
})
if(filtered.count == 0){
searchActive = false;
} else {
searchActive = true;
}
self.tableView.reloadData()
}