HIDictionaryWindowShow usage in Swift

334 views Asked by At

How do you invoke HIDictionaryWindowShow in Swift? I try this:

import Carbon

if let text = _dictionaryText, let range = _dictionaryRange
{
    let font = CTFontCreateWithName("Baskerville", 16, nil);
    let point = CGPoint(x: 0.0, y: 0.0);
    var trns = CGAffineTransform();
    HIDictionaryWindowShow(nil, text, range, font, point, false, &trns);
}

But getting error

Cannot invoke 'HIDictionaryWindowShow' with an argument list of type '(nil, String, CFRange, CTFont!, CGPoint, Bool, CGAffineTransform)'

Not seeing the wrong argument here. First and last argument should be allowed to be nil but docs say that NULL is Ok as the first argument which is nil in Swift or is it? As there is no NULL in Swift what do I need to specify instead of it?

1

There are 1 answers

0
Neil On

Sorry I don't have the Swift code, but you can probably work from the following untested objective-c code. Note that showDefinitionForAttributedString was added to replace HIDictionaryWindowShow which is, as you know, a carbon function and won't be supported forever.

    [self.view showDefinitionForAttributedString:[[NSAttributedString alloc] initWithString:text] atPoint:NSMakePoint(0.0, 0.0)];

EDIT:

In looking further the second argument is not correct in your example. Carbon lib does not understand String, it wants CFTypeRef.