gpt4 book ai didi

swift - 在 Swift 中读取双 *

转载 作者:行者123 更新时间:2023-11-28 16:12:18 27 4
gpt4 key购买 nike

我有一个返回 double * 的 Obj-C 方法,如何在 Swift 中将其作为 Double 访问?

我收到这个错误

Cannot convert value of type 'UnsafeMutablePointer<Double>' to expected argument type 'Double'

我调用这个 - (double * _Nonnull) modIntensityForDestination:(int) destination;

当我这样做时失败了

let intensity = audioEngine.modIntensityForDestination(Int32(modDestinationID))

我已经尝试过 withUnsafeMutablePointer 但似乎无法正常工作。

最佳答案

如果该方法返回一个指向单个 float 的指针然后你可以用 .memory 取消引用它:

let intensity = audioEngine.modIntensityForDestination(...).memory

在 Swift 3 中,它将是 .pointee

关于swift - 在 Swift 中读取双 *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39410935/

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