Selector with completion, 2 variables and time interval

不羁的心 提交于 2019-12-08 08:06:02

问题


Continuing this question

I have this function

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()
            }
        }
    }

As you can see it handles one completion and one search string.

What i'm trying to do is this

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()
        }


    }
}

In this line

perform(#selector(self.getSearch(completed:searchString:)), with object1: <How to add completion here?>, with object2: searchString, afterDelay: 0.5) 

I'm trying to figure out how to add the completion on the first object and why i cant have 2 object and afterDelay??

Is it possible for me to have those 2? And if yes, how can i extend the Perform class?

来源:https://stackoverflow.com/questions/42445868/selector-with-completion-2-variables-and-time-interval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!