( { Email = "kate-bell@mac.com"; name = "Kate Bell"; Number = "(555) 564-8583"; },{ Email = "d-higgins@mac.com"; name = "DanIEl Higgins"; Number = "555-478-7672"; })
我想根据密钥“名称”过滤这个字典
func searchbar(searchbar: UISearchbar,textDIDChange searchText: String) { let predicate = nspredicate(format:"name == %@",searchText) let filteredArray = (arrContact as NSMutableArray).filteredArrayUsingPredicate(predicate) print(filteredArray) if(filteredArray.count == 0){ searchActive = false; } else { searchActive = true; } tblData.reloadData() }
我总是从上面的swift代码得到空数组.请帮我解决这个问题.谢谢
解决方法 试试这个swift 3func 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()}总结
以上是内存溢出为你收集整理的swift2 – 在Swift中过滤字典数组全部内容,希望文章能够帮你解决swift2 – 在Swift中过滤字典数组所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)