2015-06-16 23 views
0

你如何在Swift中調用HIDictionaryWindowShow?我試試這個:HIDictionaryWindowShow在Swift中的用法

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); 
} 

但得到錯誤

不能援引 'HIDictionaryWindowShow' 與 類型的參數列表 '(NIL,字符串,CFRange,CTFont!CGPoint,布爾,CGAffineTransform)'

這裏沒有看到錯誤的參數。第一個和最後一個參數應該被允許爲nil,但是docsNULL是OK,因爲第一個參數是在Swift中是nil還是它?由於Swift中沒有NULL,我需要指定什麼來代替它?

回答

0

對不起,我沒有Swift代碼,但你可以從下面未經測試的Objective-C代碼工作。請注意,添加showDefinitionForAttributedString是爲了替換HIDictionaryWindowShow,如您所知,它是一個碳函數,並且不會永遠支持。

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

編輯:

在進一步尋找第二個參數是不是在你的例子是正確的。碳庫不理解String,它想要CFTypeRef

相關問題