这就是我目前正在做的事情,它过滤数组但不正确.
例如,假设我使用“MID”搜索数组中的项目我有一个应该显示的项目但是显示的项目以“Bad”开头.
var array = brewerIEs.filter() {struct BrewerIEs { let name: String? let breweryID: String? let distance: Double? let largeIconURL: String? let streetAddress: String? let locality: String? let region: String? let phone: String? let website: String? init(brewDictionary: [String: AnyObject]) { name = brewDictionary["brewery"]?["name"] as? String breweryID = brewDictionary["breweryID"] as? String distance = brewDictionary["distance"] as? Double largeIconURL = brewDictionary["brewery"]?["images"]??.objectForKey("large") as? String streetAddress = brewDictionary["streetAddress"] as? String locality = brewDictionary["locality"] as? String region = brewDictionary["region"] as? String phone = brewDictionary["phone"] as? String website = brewDictionary["website"] as? String }}.name?.lowercaseString.rangeOfString(searchController.searchbar.text.lowercaseString) != nil } results = array
这是我的结构
let array = brewerIEs.filter() { (.name!.lowercaseString as Nsstring).containsstring(searchController.searchbar.text.lowercaseString)}
请指出正确的方向!
注意:我使用的是Swift 1.2
更新:
我认为视频有助于更好地解释我想要做的事情.
Demo Of issue
我想要的是找到过滤数组,以便只显示具有类似名称的项目.
更新2:事实证明,当我的UISearchController处于活动状态时,我忘了处理这个案例.
解决方法 假设您的Struct名称是BrewerIEs并且它具有name属性,请尝试以下 *** 作: 总结以上是内存溢出为你收集整理的arrays – Swift 1.2按关键字过滤一个Structs数组全部内容,希望文章能够帮你解决arrays – Swift 1.2按关键字过滤一个Structs数组所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)