-1

I'm using NSTextField with complections and they work fine by pressing F5 key.

But I have to call complections programmatically and I'm using complete(:) for this, but I get an error and crash every time I I tried to call InputField.complete(nil).

You can find my code below.

Thank you in advance

My code:

class ViewController: NSViewController, NSTextFieldDelegate, NSControlTextEditingDelegate {

@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 in my console:

pressed
[NSTextField complete:]: unrecognized selector sent to instance 0x10066ae00
[General] -[NSTextField complete:]: unrecognized selector sent to instance 0x10066ae00

1 Answers1

0

This works:

@IBAction func completeButton(_ sender: NSButton) {
    inputField.currentEditor()?.complete(nil)
}