Skip to Content
0

Search/Filter EntitySet without Navigation Property

Aug 02, 2017 at 02:25 PM

37

avatar image
Former Member

Hi,

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 https://www.sap.com/developer/tutorials/fiori-ios-scpms-floorplan.html

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.allValues.map({ (collectionType) -> String in
    return collectionType.rawValue
    })
func updateSearchResults(for searchController: UISearchController) {

        guard let searchString = searchController.searchBar.text, !searchString.isEmpty else {
            self.isFiltered = false
            self.filteredCustomers.removeAll()
            self.tableView.reloadData()
            return
        }
        self.isFiltered = true
        self.filteredCustomers = self.appDelegate.collections[0].filter( {
            return
                $0.name1!.contains("LINDNER")
        })
        self.tableView.reloadData()
    }
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
0

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({
            $0.contains("LINDNER")
        })

Regards,
Florian

Share
10 |10000 characters needed characters left characters exceeded