I want to create autocomplete list like this for NSTextField
:
I have found this: https://developer.apple.com/documentation/appkit/nscontroltexteditingdelegate/1428925-control
optional func control(_ control: NSControl,
textView: NSTextView,
completions words: [String],
forPartialWordRange charRange: NSRange,
indexOfSelectedItem index: UnsafeMutablePointer<Int>) -> [String]
Can somebody please explain how to use this on any example? I can't really understand.
I tried to implement this, but nothing works. You can find my code below.
Thank you in advance
My code:
class ViewController: NSViewController, NSTextFieldDelegate {
@IBOutlet weak var InputField: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
InputField.delegate = self
}
func control(_ control: NSControl, textView: NSTextField, completions words: [String], forPartialWordRange charRange: NSRange, indexOfSelectedItem index: UnsafeMutablePointer<Int>) -> [String] {
let words = ["Hello", "Brother"]
return words
}
@IBAction func CompleteButton(_ sender: NSButton) {
print("pressed")
InputField.complete(nil)
} }
But if I try to press the button, I get this error in my console:
pressed
[NSTextField complete:]: unrecognized selector sent to instance 0x10066ae00
[General] -[NSTextField complete:]: unrecognized selector sent to instance 0x10066ae00