Objective-C中有以下代码:
#import <Carbon/Carbon.h>
TISInputSourceRef inputSource = TISCopyCurrentKeyboardLayoutInputSource();
CFDataRef layoutData = (CFDataRef)TISGetInputSourceProperty(inputSource, kTISPropertyUnicodeKeyLayoutData);
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);
我正在尝试将其转换为Swift,到目前为止,我已经拥有了:
import Carbon
let inputSource = TISCopyCurrentKeyboardLayoutInputSource()
let layoutData = TISGetInputSourceProperty(inputSource!.takeRetainedValue(), kTISPropertyUnicodeKeyLayoutData) as! CFData
let keyboardLayout = CFDataGetBytePtr(layoutData) as? UnsafePointer<UCKeyboardLayout>
// Cast from 'UnsafePointer<UInt8>?' to unrelated type 'UnsafePointer<UCKeyboardLayout>' always fails
我需要keyboardLayout
成为UnsafePointer<UCKeyboardLayout>
而不是UnsafePointer<UInt8>
,以便可以将其传递到UCKeyTranslate
的keyLayoutPtr
参数中。
我该如何投放?