So I'm migrating some of my old ObjC code into Swift, and have run into an inexplicable error that's basically stopped me in my tracks. Would love some help or insight:
I have a subclass of NSTextView that in a couple of places needs to call delegate methods (NSTextViewDelegate). When I convert this code from this:
NSArray *options = [self.delegate textView:self completions:@[] forPartialWordRange:_autocompletionRange indexOfSelectedItem:&index];
which works just fine, to this:
guard
let options = delegate?.textView(self, completions:[], forPartialWordRange:autocompletionRange, indexOfSelectedItem:&index) as? ContextOption
else { return }
I get a compile-time error at:
let options = delegate?.textView(self, completions:[], forPartialWordRange:autocompletionRange, indexOfSelectedItem:&index) as? ContextOption
^
saying: "Value of optional type '((NSTextView, completions: [String], forPartialWordRange: NSRange, indexOfSelectedItem: UnsafeMutablePointer<Int>) -> [String])?' not unwrapped; did you mean to use '!' or '?'?"
It wants me to unwrap 'textView' in that function call which is obviously not right:
let options = delegate?.textView?(self, completions:[], forPartialWordRange:autocompletionRange!, indexOfSelectedItem:&index) as? ContextOption
Any ideas?