我有一個C函數需要一個指針。 我想從Swift中調用它。將inout值轉換爲UnsafeMutablePointer <非託管<TYPE>?>
從Calling C function from Swift(和個人經驗),做& var不起作用。
不過,我不能夠施展&變種成UnsafeMutablePointer ......也沒有任何類型的轉換(如VAR分配的地址類型UnsafeMutablePointer的另一個變量)
(假設類型是一個對象)
感謝
示例代碼:
var zero = CreateCompressionSession(&session as UnsafeMutablePointer<Unmanaged<VTCompressionSession>?>, Int32(CVPixelBufferGetWidth(pixelBuffer)), Int32(CVPixelBufferGetHeight(pixelBuffer)))
而試圖讓它撥打:
int CreateCompressionSession(VTCompressionSessionRef* session, int width, int height) {
OSStatus err = VTCompressionSessionCreate(NULL, width, height, kCMVideoCodecType_H264, NULL, NULL, NULL, (VTCompressionOutputCallback)vtCallback, NULL, session);
NSLog(@"%d %p", (int)err, session);
if (err == noErr) {
return 0;
} else {
return err;
}
}
您是否檢查過Apple的指南,以便從Swift使用C? https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html和https://developer.apple.com/swift/blog/?id=6 –
是的,不確定是否只是我,但他們使用&VAR,它的工作(雖然他們迅速執行快速功能?有點奇怪...)。但我得到錯誤。我沒有閱讀這些文檔的內容嗎? – dcheng