Ios Can';t在集合SearchBarController中使用/contains运算符

Ios Can';t在集合SearchBarController中使用/contains运算符,ios,swift,uisearchbar,Ios,Swift,Uisearchbar,当我第一次点击搜索栏时,我试图使用搜索栏搜索数组 无法将in/contains运算符用于集合 我的代码如下……我是Swift搜索栏的新手,因此非常感谢您的帮助 struct Objects{ var sectionName = String() var sectionObjects = [String]() } var objectsArray = [Objects]() var filteredTableData = [String]() lazy var resultSe

当我第一次点击搜索栏时,我试图使用搜索栏搜索数组

无法将in/contains运算符用于集合

我的代码如下……我是Swift搜索栏的新手,因此非常感谢您的帮助

 struct Objects{
    var sectionName = String()
    var sectionObjects = [String]()
}
var objectsArray = [Objects]()
var filteredTableData = [String]()
lazy  var resultSearchController = UISearchController()


@IBOutlet weak var searchBar: UISearchBar!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    objectsArray = [Objects(sectionName: "A", sectionObjects: ["A&W Restaurant","Applebee's","Arby's","Arthur Treacher","Atlanta Bread Company","Au Bon Pain","Auntie Anne's"]),
                    Objects(sectionName: "B", sectionObjects: ["Backyard Burgers","Baja Fresh","Baskin-Robins","BD's Mongolian Grill","Beard Papa's","Big Apple Bagels","Biggby","Blackjack Pizza","Blimpie","Bob Evans Restaurant","Bojangles","Boloco","Boston Market Restaurant","Boston's Gourmet Pizza USA","Braum's","Breadsmith","Brown's Chicken & Pasta","Bruegger's","Bruster's","Buca Di Beppo","Buffalo Wild Wings","Burger King", "Burgerville"]),
                    Objects(sectionName: "C", sectionObjects: ["California Pizza Kitchen","Camille's Sidewalk Cafe","Captain D's Seafood","Caribou Coffee","Carl's Jr.","Carl's Jr. Green Burrito","Carraba's","Carvel","Casey's General Store","Cedarlane","Charley's Grilled Subs","Checkers/Rally's","Chevys Fresh Mex","Chick-fil-a","Chicken Express","Chicken Out Rotisserie","Chili's","Chipolte","Chuck E. Cheese","Church's Chicken", "Cici's Pizza","Cinnabon","Claim Jumper","Coffee Bean & Tea Leaf","Cold Stone Bakery Cafe","Cosi","Costco Food Court","Cousins Subs","Crispers","Culver's"]),
                    Objects(sectionName: "D", sectionObjects: ["D'Angelo","Dairy Queen","Daphne's Greek Cafe","Davanni's","Daylight Donuts","Del Taco","Denny's","Dickey's Barbecue Pit","Dippin' Dots","Domino's Pizza","Don Pablos","Donatos Pizza","DoubleDave's PizzaWorks","Dunkin' Donuts","Dunn Bros Coffee","Dutch Bros"]),
                    Objects(sectionName: "E", sectionObjects: ["East of Chicago","Eat 'n Park","Edo Japan","Einstein Bros Bagels","El Pollo Loco","Elephant Bar Restaurant","Erbert & Gerbert's","Extreme Pita"]),
                    Objects(sectionName: "F", sectionObjects: ["Famous Dave's BBQ Restaurant","Fatburger","Fazoli's Italian Food","Firehouse Subs","First Watch","Five Guys","Flame Broiler","Fox's Pizza Den","Freshens Smoothie Company","Friendly's","Frisch's Big Boy","Frullati"]),
                    Objects(sectionName: "G", sectionObjects: ["Gloria Jeans","Godfather's Pizza","Gold Star Chili","Golden Corral","Golden Spoon Frozen Yogurt","Good Times","Great American Bagel","Great Steak & Potato Company","Great Wraps"])
    ]

    self.resultSearchController = ({
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = self
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()

        self.tableView.tableHeaderView = controller.searchBar

        return controller
    })()

    self.tableView.reloadData()

}
func updateSearchResults(for searchController: UISearchController) {


    filteredTableData.removeAll(keepingCapacity: false)

    let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text!)
    let array = (objectsArray as NSArray).filtered(using: searchPredicate)
    filteredTableData = array as! [String]

    self.tableView.reloadData()
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! UITableViewCell!
    if (self.resultSearchController.isActive) {
        cell?.textLabel?.text = filteredTableData[indexPath.row]

        return cell!
    }
    else{
        cell?.textLabel?.text = objectsArray[indexPath.section].sectionObjects[indexPath.row]
        return cell!

    }
}

你检查过了吗?是的,当我尝试那行代码时,它阻止了错误的发生,但它没有搜索任何内容@oopery你最好在你的问题中包括你尝试过的内容。您的问题在任何时候都会被标记为重复,如果没有,则可能会重复