Search Array of Dictionaries for Value in Swift

后端 未结 6 517
你的背包
你的背包 2020-12-16 01:50

I\'m new to Swift and taking a class to learn iOS programming. I find myself stumped on how to search in an array of dictionaries for a string value and dump the string valu

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 02:17

    i have array of customer ,each customer having name,phone number and other stubs .so i used the below code to search by phone number in the array of dictionary in search bar

     for  index in self.customerArray
        {
            var string = index.valueForKey("phone")
            if let phoneNumber = index.valueForKey("phone") as? String {
                string = phoneNumber
            }
            else
            {
                string = ""
            }
            if string!.localizedCaseInsensitiveContainsString(searchText) {
                filtered.addObject(index)
                searchActive = true;
            }
    
        }
    

提交回复
热议问题