Skip to Content

Search/Filter EntitySet without Navigation Property

Aug 02, 2017 at 02:25 PM


avatar image
Former Member


i have a list of Customers at the Master view and want to filter them via search bar.

i implemented the search function as described at

but i don´t know how to filter my collection due to the fact that xcode is telling me that the collection does not have the function "filter"

self.appDelegate.colletions is defined like that:

var collections ={ (collectionType) -> String in
    return collectionType.rawValue
func updateSearchResults(for searchController: UISearchController) {

        guard let searchString = searchController.searchBar.text, !searchString.isEmpty else {
            self.isFiltered = false
        self.isFiltered = true
        self.filteredCustomers = self.appDelegate.collections[0].filter( {
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Florian Pfeffer
Aug 03, 2017 at 01:45 PM

Hm, your "collections" property seems to be "just" an array of strings (created by the map function executed on CollectionType.allValues), you will get the error, because you try to execute the "filter" method on the first element of that array (which is just a string, and not a structured value on which you can access the "name1" property). With Swift 3.0 a string has no filter function cause it is no collection anymore (with Swift 4 this was changed again, String is again a collection which supports filtering).

But of course you do not wanna execute a filter on the first string only. I assume that wanna filter the array of Strings. So you can write following if you just wanna have the string value. If you need your structured "customer" your collection has to look different:

 self.filteredCustomers = self.appDelegate.collections.filter({


10 |10000 characters needed characters left characters exceeded