gpt4 book ai didi

IOS,从 Obj-c 转换为 swift

转载 作者:搜寻专家 更新时间:2023-10-31 22:49:09 25 4
gpt4 key购买 nike

谁能帮我把这个方法转换成swift?

-(void) camera:(DJICamera*)camera didReceivedVideoData:(uint8_t*)videoBuffer length:(int)length {
uint8_t* pBuffer = (uint8_t*)malloc(length);
memcpy(pBuffer, videoBuffer, length);
[[VideoPreviewer instance].dataQueue push:pBuffer length:length];
}

我的翻译是下面的,但是,应用程序崩溃了。由于在这种情况下它需要通过 USB 连接到无人机,所以我无法调试它。

func camera(camera: DJICamera!, didReceivedVideoData videoBuffer: UnsafeMutablePointer<UInt8>, length: Int32)
{
VideoPreviewer.instance().dataQueue.push(videoBuffer, length: length)
}

最佳答案

我编译成功了。

func camera(camera: DJICamera!, didReceivedVideoData videoBuffer: UnsafeMutablePointer<UInt8>, length: Int32) {
// keep 'buffer' as 'var', 'let' will crash VideoPreviewer
var buffer = UnsafeMutablePointer<UInt8>.alloc(Int(length))
memcpy(buffer, videoBuffer, Int(length))
VideoPreviewer.instance().dataQueue.push(buffer, length: length)
}

关于IOS,从 Obj-c 转换为 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32351424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com