继续question
我有这个功能
func getSearch(completed: @escaping DownloadComplete, searchString: String) {
let parameters: Parameters = [
"action" : "search",
"subaction" : "get",
"product_name" : searchString,
"limit" : "0,30"
]
Alamofire.request(baseurl, method: .get, parameters: parameters).responseJSON { (responseData) -> Void in
if((responseData.result.value) != nil) {
let result = responseData.result
if let dict = result.value as? Dictionary<String, AnyObject>{
if let list = dict["products_in_category"] as? [Dictionary<String, AnyObject>] {
if self.filteredData.isEmpty == false {
self.filteredData.removeAll()
}
for obj in list {
let manPerfumes = Products(productDict: obj)
self.filteredData.append(manPerfumes)
}
}
}
completed()
}
}
}
如您所见,它处理一个完成和一个搜索字符串。
我想要做的就是这个
extension SearchViewController: UISearchResultsUpdating {
func updateSearchResults(for searchController: UISearchController) {
if (searchController.searchBar.text?.characters.count)! >= 3 {
searchString = searchController.searchBar.text!
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(self.getSearch(completed:searchString:)), object: nil)
perform(#selector(self.getSearch(completed:searchString:)), with object1: <How to add completion here?>, with object2: searchString, afterDelay: 0.5)
} else {
self.searchResultTable.reloadData()
}
}
}
在这一行
perform(#selector(self.getSearch(completed:searchString:)), with object1: <How to add completion here?>, with object2: searchString, afterDelay: 0.5)
我正在试图找出如何在第一个对象上添加完成以及为什么我不能拥有2个对象和afterDelay?
我有可能拥有这两个吗? 如果是,我如何扩展Perform类?