Filtering array of dictionaries in Swift

后端 未结 4 1032
走了就别回头了
走了就别回头了 2021-01-01 02:15

I have An Array With Dictionaries example :

(
        {
        Email = \"kate-bell@mac.com\";
        Name = \"Kate Bell\";
        Number = \"(555) 564-858         


        
4条回答
  •  -上瘾入骨i
    2021-01-01 03:00

    Try This for swift 3

    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
    
        // Put your key in predicate that is "Name"
        let searchPredicate = NSPredicate(format: "Name CONTAINS[C] %@", searchText)
        let array = (arrContact as NSArray).filtered(using: searchPredicate)
    
        print ("array = \(array)")
    
        if(array.count == 0){
            searchActive = false;
        } else {
            searchActive = true;
        }
        self.aTable.reloadData()
    }
    

提交回复
热议问题