1

I'd like to work with a private macOS framework (MultitouchSupport.framework) in a swift project and got stuck at this point.

So far I get the address of the trackpad as AnyObject: <MTDevice 0x10190b600 [0x7fff877ed5b0]>. But the methods of this framework want that first hex value as a pointer typedef void *MTDeviceRef; argument.

The ObjC code that does what I need looks like this: MTDeviceRef device = (__bridge MTDeviceRef)[deviceList objectAtIndex:i];

I have tried converting via as! MTDeviceRef and withUnsafePointer with no luck.

Is there a way to convert this? I am still new to coding and swift, any help is greatly appreciated!

Turbooo
  • 11
  • 1
  • This might be what you are looking for: https://stackoverflow.com/a/33310021/1187415. – Martin R Sep 27 '17 at 14:13
  • Nice, this is the right direction. Now I get this error: Cannot convert value of type 'UnsafeRawPointer' to expected argument type 'MTDeviceRef!' (aka 'ImplicitlyUnwrappedOptional') – Turbooo Sep 27 '17 at 14:25
  • Oh got that with a slight change. This did the trick: func bridge(obj : T) -> UnsafeRawMutablePointer { return UnsafeRawMutablePointer(Unmanaged.passUnretained(obj).toOpaque()) } – Turbooo Sep 27 '17 at 14:34
  • Yes, my conversion functions assume *constant* pointers. I'll update the code for mutable pointers later. – Martin R Sep 27 '17 at 14:52

0 Answers0