NSTokenField suggestion list built with any matching part of the entered string

134 Views Asked by At

I want the suggestion list, built with any matching part of the entered string, not with a prefix.

I build the suggestlionlist like this:

func tokenField(_ tokenField: NSTokenField, completionsForSubstring substring: String, indexOfToken tokenIndex: Int, indexOfSelectedItem selectedIndex: UnsafeMutablePointer<Int>?) -> [Any]?
{ let allNames = ["aaaOneaa", "aaaTwoaa", "aaaThreeaa"]
  let matching = allNames.filter { $0.lowercased().contains(substring.lowercased()) }

  return matching
}

The building of the suggestion list works fine.

My problem is. If the user enters "T" in the NSTokenFiled in the suggestion list "aaaTwoaa" and "aaaThreeaa" appear, as wanted. In the NSTokenfield now "a" is selected as first character.

How can I keep "T" as selected character, so that the user can type "h" to get "aaaThreeaa?

0

There are 0 best solutions below