Extra argument In Call When Using Searchbar

4130 views ios

I am getting the error 'Extra Argument in Call' when I am trying to implement a search bar into my app.

I have read other questions that include:

Swift - Extra Argument in call

Swift 4 “Extra argument in call” Rxswift

And others but have come up with no success.

Here is my code:

extension ViewController: UISearchBarDelegate {

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {

    todoItems = todoItems.filter("title CONTAINS[cd] %@", searchBar.text!).sorted(byKeyPath: "dateCreated", ascending: true) // Getting Error on this line



func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
    if searchBar.text?.count == 0 {

        DispatchQueue.main.async {



answered question

Thanks to anyone who helps!

What is the type of todoItems? Is it Results<T> from Realm database?

1 Answer


You are mixing up NSPredicate and filter syntax as well as NSSortDescriptor and sorted syntax.

Assuming todoItems contains an array of a custom struct or class the native Swift way is

todoItems = todoItems.filter{ $0.title.range(of: searchBar.text!, options: [.caseInsensitive, .diacriticInsensitive]) != nil}
                     .sorted{ $0.dateCreated < $1.dateCreated}

posted this

Have an answer?


Please login first before posting an answer.